Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / March 2006

Tip: Looking for answers? Try searching our database.

Compilation of managed code (IL) into native code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Manoj Agarwal - 27 Feb 2006 07:15 GMT
I had a question about some of the basic concepts and needed help.

When one runs a managed app then the CLR compiles the managed IL code into
native code. Is this done for the full application or just for the function
called?

I earlier thought that the code of the full application is converted to
native code and then this native code is cached so that for future runs of
this app this step is not needed and the native code can be directly run. But
now I am not sure.

Also, is the native code cached? Is the cache retained between machine
reboots? Can one configure the duration the cache is maintained?

Thanks,
- Manoj
Jon Skeet [C# MVP] - 27 Feb 2006 07:28 GMT
> I had a question about some of the basic concepts and needed help.
>
> When one runs a managed app then the CLR compiles the managed IL code into
> native code. Is this done for the full application or just for the function
> called?

On the desktop framework it occurs the first time any particular method
is called. On the compact framework I *think* it's done a class at a
time, but I can't remember for sure.

> I earlier thought that the code of the full application is converted to
> native code and then this native code is cached so that for future runs of
> this app this step is not needed and the native code can be directly run. But
> now I am not sure.

You can do that with ngen.exe.

> Also, is the native code cached? Is the cache retained between machine
> reboots? Can one configure the duration the cache is maintained?

No, the native code isn't cached unless you use ngen.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Manoj Agarwal - 01 Mar 2006 13:52 GMT
Thanks for the reply Jon.

Its not clear to me what you meant for desktop app- when a method is called
for the first time then is the full app converted to native code or just that
method\class?

Also, I have noticed that if you run a managed app then time taken is more
on the first run and its almost always faster after that. You can write a
Hello World app and run it multiple times to confirm this. This makes me
believe that there might be some caching of the native code which the CLR
does. Your thoughts...

- Manoj

> > I had a question about some of the basic concepts and needed help.
> >
[quoted text clipped - 17 lines]
>
> No, the native code isn't cached unless you use ngen.
Willy Denoyette [MVP] - 01 Mar 2006 17:55 GMT
No, the caching is done by the OS in the file system cache for non ngen'd
images or on XP and higher in the prefetch (disk) cache for native images
(as the ngen'd images).
A non Ngen'd image (just a regular file) is loaded by the OS using normal
file IO, that means that the assembly passes the cache where it stays until
it's removed in favor of other files. When you load a program a second time
(after the first one has gone) and the file data is still in cache, it will
get loaded from the cache, that's why it loads so fast the second time.
An Ngen'd image is loaded differently, here the OS loader loads the code
image in memory (actually it maps the data into the process space) bypassing
the FS cache completely.
However on XP and higher, the OS keeps part of the loaded native image in
the prefetch directory (under \windows) , which it loads as part of the boot
process. That means that programs that have been loaded recently (the
threshold is a couple of days depending on the size and number of images
loaded) are partly preloaded to speed-up the final load process.

Willy.

| Thanks for the reply Jon.
|
[quoted text clipped - 31 lines]
| >
| > No, the native code isn't cached unless you use ngen.
Jon Skeet [C# MVP] - 01 Mar 2006 19:20 GMT
> Thanks for the reply Jon.
>
> Its not clear to me what you meant for desktop app- when a method is called
> for the first time then is the full app converted to native code or just that
> method\class?

Just the method.

> Also, I have noticed that if you run a managed app then time taken is more
> on the first run and its almost always faster after that. You can write a
> Hello World app and run it multiple times to confirm this. This makes me
> believe that there might be some caching of the native code which the CLR
> does. Your thoughts...

You'll see that on plenty of applications. All it means is that the
binaries and libraries required by the app are then in the file system
cache, so don't need to be loaded from the disk.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.