The book says that when the program starts it is compiled into machine code from IL, and each time the program is started before the computer is turned off or restarted, the already compiled program will be launched, otherwise it will be re-compiled from IL into the machine code by the JIT compiler. Is it so? Is there more detailed information about this process?

  • one
    CLR via C# - J. Richter - for more information. To the question "Is this so?" the answer is it depends. You can knock into machine code once for a specific deployment environment. There is a lot more information you can find that - Books on C # and other literature in the section Книги для специалистов: внутренние механизмы и пыльные углы - Anton Komyshan

1 answer 1

When the CLR executes the IL code, the following happens: when the IL block is called, the JIT compiler checks and converts it into machine instructions that it stores in a dynamic memory block. Then, it returns to the data structure of the type and replaces the address of the method being called with the address of this memory block, and the next request will not recompile and the already compiled code will be used.

Now, directly, the answer to your question : no, all compiled code is stored in dynamic memory, which means that this code is destroyed when you exit the application.

At the same time, there is a way to precompile an application to a machine image (Native Image) using the Native Image Generator (Ngen.exe)

  • Add about NGen.exe, I think it will be useful. - Anton Komyshan
  • What do you mean by a data type structure? Where is she from? - Vladimir Smirnov
  • The data structure here refers to the type, and the "IL-code block" method of this type. - Artyom Okonechnikov