C # code compilation and execution (excerpt from MS inside C #)

Source: Internet
Author: User
Compile | process | Execute 1.YOU write source code in C #.

2.You then compile it using the C # compiler (csc.exe) into an EXE.

3.The C # compiler outputs the MSIL code and a manifest into a read-only part of the EXE that has a standard PE (win32-port Able executable) header.
So far good. However, here ' s the important part:when the compiler creates the output, it also imports a function named _ Corexemain fr Om the. NET runtime.

4.When the application is executed, the operating system loads the PE, as OK as any dependent dynamic-link (DL Ls), such as the one that exports the _ Corexemain function (Mscoree.dll), just as it does and any valid PE.
The 5.The operating system loader then jumps to the entry point inside the PE, which are put there by the C # compiler. Once again, this is exactly it is executed in Windows.
However, since the operating system obviously can ' t execute the MSIL code, the entry point are just a small stub that jumps To the _ Corexemain function in Mscoree.dll.

6.The _ Corexemain function starts the execution of the MSIL code that is placed in the PE.

7.Since MSIL code cannot be executed directly-because it's not on a machine-executable format-the CLR compiles the MSIL by Using a just-in-time (JIT) compiler (or jitter) into the native CPU instructions as it processes the MSIL. JIT compiling occurs as methods in the program are called. The compiled executable code is cached on the machine and are recompiled only if there ' s some change to the source code.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.