Reputation: 31
I'm reading second book and it's still not obvious.
My question is: How many times IL language is compiled: a) Every time from the beginning durning the execution of application. b) Once, after first execution.
Upvotes: 3
Views: 303
Reputation: 32578
It's a) -Every time the program is executed. As bits of the assemblies are executed, the JITter compiles and caches them in memory. So each bit is only compiled once before it's run, then run natively each time after that. However, these compiled bits are only stored in memory and are thrown away after the program terminates.
If you want to, you can you can use ngen
to create and cache compiled images, in which case the answer becomes C) - Once, before execution.
An important special-case clarification ( from svick ). Note that on Windows 8, an assembly that targets .Net 4.5 or later, and is either installed into the GAC or comes from the Windows Store is a candidate for automatic native image generation. These native images are created by the scheduled NGen Task based on usage.
Upvotes: 5
Reputation: 1174
If the assembly is compiled with the AnyCPU option, then it is recompiled at execution to match the current platform. Besides that, JIT compilation can occur at any time, for example when you have generic classes.
Upvotes: 0