The CLR’s Execution Model
来源:互联网 发布:linux head命令 编辑:程序博客网 时间:2024/05/22 03:34
1.Depending on the platform switch, the C# compiler will emit an
assembly that contains either
a PE32 or PE32+ header (运行32位/64位), and the compiler will also emit
the desired CPU architecture (or
8 Part I CLR Basics
agnostic) into the header as well.
Microsoft ships two SDK command-line utilities, DumpBin.
exe and CorFlags.exe(设置Assembly以32 bit还是64 bit运行), that you can
use to examine the header information emitted in a managed module by the
compiler.一般情况下,Windows会根据Header信息来决定以什么样的方式来运行
Assembly.
2.JITCompiler is responsible for compiling a method’s IL code into
native CPU instructions.基于Stack方式来Execution.Verification 机制确保
Code是Safe。
The NGen.exe tool that ships with the .NET Framework can be used to
compile IL code to
native code when an application is installed on a user’s machine.
Struct应该确保每个值类型都有初始化
Because C# doesn’t allow value types with parameterless constructors,
compiling the following
type produces the following message: "error CS0573: 'SomeValType.m_x':
cannot
have instance field initializers in structs."
internal struct SomeValType {
// You cannot do inline instance field initialization in a value type
private Int32 m_x = 5;
}
internal struct SomeValType {
private Int32 m_x, m_y;
// C# allows value types to have constructors that take parameters.
public SomeValType(Int32 x) {
m_x = x;
// Notice that m_y is not initialized here.
}
}
When compiling this type, the C# compiler produces the following
message: "error
CS0171: Field 'SomeValType.m_y' must be fully assigned before control
leaves
the constructor."
解决方法:构造函数里面调用一个new();
// C# allows value types to have constructors that take parameters.
public SomeValType(Int32 x) {
// Looks strange but compiles fine and initializes all fields to 0/null
this = new SomeValType();
m_x = x; // Overwrite m_x’s 0 with x
// Notice that m_y was initialized to 0.
}
//经过试验,以下言论被证明错误!!!!!!
永远不要在值类型里写一个static constructor,因为CLR永远不会调用值类型的
静态构造函数!!!!
Important While you can define a type constructor within a value type,
you should never actually
do this because there are times when the CLR will not call a value type’
s static type constructor.
Here is an example:
internal struct SomeValType {
static SomeValType() {
Console.WriteLine("This never gets displayed");
}
public Int32 m_x;
}
public sealed class Program {
public static void Main() {
SomeValType[] a = new SomeValType[10];
a[0].m_x = 123;
Console.WriteLine(a[0].m_x); // Displays 123
}
}
Extension Method(不包括属性,事件,操作符,等等)对已有类型增加新的方法亮
点:1,Static Class 2.Static Method. 3参数前面加this关键字
public static class Test
{
public static int IndexOf(this StringBuilder sb, char value)
{
return 0;
}
}
Having immutable strings also means that there are no thread
synchronization issues when
manipulating or accessing a string. In addition, it’s possible for the
CLR to share multiple
identical String contents through a single String object.
For performance reasons, the String type is tightly integrated with the
CLR. Specifically, the
CLR knows the exact layout of the fields defined within the String type,
and the CLR accesses
these fields directly. This performance and direct access come at a
small development cost:
the String class is sealed, which means that you cannot use it as a base
class for your own
type.
AppDomains
When the CLR COM server initializes, it creates an AppDomain. An
AppDomain is a logical
container for a set of assemblies. The first AppDomain created when the
CLR is initialized is
called the default AppDomain; this AppDomain is destroyed only when the
Windows process
terminates.
1.Objects created by code in one AppDomain cannot be accessed directly
by code in
another AppDomain
2.AppDomains can be unloaded The CLR doesn’t support the ability to
unload a single
assembly from an AppDomain.
3.AppDomains can be individually secured
4.AppDomains can be individually configured
- The CLR’s Execution Model
- The CLR’s Execution Model
- CLR ViA C# 2/Chapter 1 The CLR’s Execution Model CLR/1
- [CLR via C#]1#The CLR's Execution Model WORK-IN-PROGRESS
- CLR Via C# Note--The CLR's execution mode
- Play application's execution model.
- The CLR's Thread Pool
- CLR 2.0 Memory Model
- SPID Execution Model
- TinyOS Tutorials——1.2 Modules and the TinyOS Execution Model
- 1.3. 执行模型 Execution Model
- [译]What is the Web's Model of Computation?
- The Graphics Execution Manager
- Python的执行模型(Execution Model)
- .NET Under The hoop -- CLR
- Understanding Swing’s Model
- app_code's class model
- The Fallacy of Perfect Execution
- 【Java&Android开源库代码剖析】のandroid-smart-image-view
- 分花生游戏 (博弈论)
- rgb颜色转换(16进制->10进制)
- Phalcon 常用函数 方法
- OScache的安装与配置
- The CLR’s Execution Model
- Delphi遍历文件夹及子文件夹(可查找固定格式文件)
- What’s New For Parallelism in .NET 4.5
- js使用heatmap热力图的一些操作
- Ps修改图片透明度
- MCI编程
- C# 中的委托和事件
- redhat5.3 DNS服务器配置
- Delphi中资源文件使用详解