Information Technology Reference
In-Depth Information
Compiling to Native Code and Execution
The program is not compiled to native machine code until it is called to run. At run time, the
CLR performs the following steps (as shown in Figure 1-4):
￿
It checks the assembly's security characteristics.
￿
It allocates space in memory.
￿
It sends the assembly's executable code to the Just-In-Time ( JIT) compiler , which com-
piles portions of it to native code.
The executable code in the assembly is compiled by the JIT compiler as it is needed, and
cached in case it is called again later in the program. That way, the code only has to be com-
piled to native code once. Code that is not called is not compiled to native code.
Figure 1-4. Compilation to native code occurs at run time
Once the CIL is compiled to native code, the CLR manages it as it runs, performing such
tasks as releasing orphaned memory, checking array bounds, checking parameter types, and
managing exceptions. For this reason
￿
Code written for the .NET Framework is called managed code , and needs the CLR.
￿
Code that does not require the CLR is called unmanaged code .
Microsoft also supplies a tool called the Native Image Generator , or Ngen , which takes an
assembly and produces native code for the processor.
Search WWH ::




Custom Search