Today I read several blog posts from my predecessors, but I have never paid attention to this concept. I will sort them out today:
Reference blog: http://www.cnblogs.com/wuchang/archive/2006/12/07/584997.html
Http://www.cnblogs.com/springcsc/archive/2008/12/25/1362515.html
Generally, an executable file contains a PE Header. The system finds the entry function based on the PE information and executes the executable program by executing the code in the entry function. The hosted program file also contains a CLR header file and other information required by CLR compared to the unmanaged program.
(1) Execution Process of unmanaged programs
In an unmanaged program, the executable program saves the machine code, and the CPU can be directly loaded and executed. After the system loads the executable program, the system adds an offset address to the base address of the executable file to form the actual physical address and directly loads it into the memory for running.
(2) the execution process of the hosting program
The executable file of the managed program contains the intermediate language and metadata. Of course, it cannot be run directly. The CLR must be started, and the CLR can instantly compile the intermediate language into machine code, and load it into the memory for execution (specific process: the program jumps to MSCoree before entering the entry function. dll, call its code to start CLR and complete some initialization work ). Of course, the method in IL is not compiled every time it is called, but compiled only when it is called for the first time, the instant compiler stores the method name and corresponding entry address in the ing table. When this method is called next time, the ing table is directly used instead of being compiled again.
Because the compiler must compile the managed program into executable code before it runs, the efficiency will decrease, but the actual decrease will be much lower. Let's take a look at the experiment below.