Click to See Complete Forum and Search --> : Why do we need IL?


Robert113355
January 31st, 2002, 01:36 PM
Why is it necessary to create an IL, and have a virtual machine? I understand that it allows us to control references and stuff without an explicit destructor, and such. Then, why can't it do it before hand and just add an extra step and pre compile to native win32 executables as well?

Could someone explain why this is too complex?

Brad Jones
January 31st, 2002, 04:41 PM
The answer I've heard most to this question is "portability" or more so, "easy portability without recompiling">

The IL allows me to create an EXE that can be ported (aka simply copied) to any platform running .NET. By creating apps that only go to the level of IL, I am removed from the non-portable issues of tapping into the OS and hardware. Sooo.... when .NET is ported to Linux, I can simply copy my .exe file to the linux machine and it will work. No recompile (like in C/C++) necessary.

Portability.

This is just one reason.

Robert113355
January 31st, 2002, 06:31 PM
I understand the future portablilty issue, however I guess there is another part of the question. Why do they need a Virtual machine that is always on. I guess I am asking why they cannot just include an automatic compiler that upon transfer of the program file in question it is automatically fully compiled to native code for that platform. The IL could be the sort of middle man between these platforms, but why is a VM necessary to relook at the code every few milliseconds or when ever it does?

Arild Fines
February 2nd, 2002, 12:37 PM
In reply to:

guess I am asking why they cannot just include an automatic compiler that upon transfer of the program file in question it is automatically fully compiled to native code for that platform.



This is more or less what happens. IL executables dont run under a VM per se, they are Just-In-Time compiled at runtime. So when you start your application, the JIT compiles your IL into native code as it is being run. You can also pre-JIT the IL into a native image with the ngen.exe tool supplied with the SDK.

"My own view on religion is that of Lucretius. I regard it as a disease born of fear and as a source of untold misery to the human race. I cannot, however, deny that it has made some contributions to civilization. It helped in early days to fix the calendar, and it caused Egyptian priests to chronicle eclipses with such care that in time they became able to predict them. These two services I am prepared to acknowledge, but I do not know of any others." -- Bertrand Russell (From his essay Has Religion Made Useful Contributions to Civilization?, first published in 1930)