Results 1 to 12 of 12

Thread: About compiling and running C# apps

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    About compiling and running C# apps

    My C# books are pretty much mentioning this with one sentense. But I like to know what is going on under the hood here. And I don't get it 100%.



    When you compile a C# app. Then it is compiled to MSIL? Right/Wrong?

    and then when you run it, then it is actualy compiled to native language?




    If both of these are true. Does that mean that when you compile it on a Win platform. Can you then take it to a linux machine that has the ,NET framework and run it there. BUT if you first run it on the Windows machine after you compiled it there, you can't bring it over to a Linux machine? Or is it "compiled" to native code every time you start the app? (not likely).

    All this seems a bit weird to me. What did I not understand?


    ØØ

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: About compiling and running C# apps

    Its a concept called "Just In Time" (JIT) compilation. When you go to execute a .NET assembly, the .NET VM compiles it into native code and caches it for future use. When the cached copy becomes out of date, because of a recompile, or whatever, a fresh copy is compiled again from the assembly.

    So you can use the assembly anywhere that has the framework. The original assembly is not affected by the JIT compiler.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: About compiling and running C# apps

    Ohhh...so the natvie code is cashed somewhere else then in the binary file that is compiled???



    I read this, and that was why I started to wonder:

    This is actually a common misconception. I mean you state that one of the languages runs on a VM but neither of the languages you stated do.

    Maybe you just don't understand how C# and the .NET framework are working under the hood? Maybe you just didn't know that C# compiles to MSIL code and on first run is JIT on the fly and compiled to NATIVE code and never touches any type of VM?

    He says C# apps isn't touching any VB at all. Is that right?



    ØØ

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: About compiling and running C# apps

    He's right. Why would it? C# and VB are separate languages. Live like VB6 and C++ are separate. Where commonalities are is in the Framework itself. When you access System.Data.String, it's the same object in both VB.NET and C#. Unlike previously, they would have been in different DLL (msvbrunXX.dll & msvcrun.dll)

    When you compile a VB.NET or C#.NET proggie, it gets compiled into a IL object, that is "finished" upon execution via the JIT compiler.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: About compiling and running C# apps

    But when it gets "finished". Does it use the a VM then?

    And if I understood crptcblade right, you can still take the compiled version with you too an other OS with the .NET framwork. Because it will again be "finished" off by the JIT compiler?

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: About compiling and running C# apps

    THere is no VM. THere's nothign virtual about it. Once it's "finished" it runs as a fully compiled unit and is cached. As for being able to freely move he assemblies around from OS to OS.... I don't know. I haven't a need to do that so I've never tried it. Would be interested in the results though.

    Something in the back of my brain says it can't be that easy, there *has* to be a catch.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: About compiling and running C# apps

    Quote Originally Posted by techgnome
    THere is no VM. THere's nothign virtual about it. Once it's "finished" it runs as a fully compiled unit and is cached.
    Thanks. Got it now......I need it smacked in my for head to understand thing...

    Quote Originally Posted by techgnome
    As for being able to freely move he assemblies around from OS to OS.... I don't know. I haven't a need to do that so I've never tried it. Would be interested in the results though.

    Something in the back of my brain says it can't be that easy, there *has* to be a catch.

    Tg

    Yeah, it sounds a bit too god to be true. But it would be interesting to hear if anyone have tried it. Well it works for java, so why not...but it isn't done 100% in the same way though.



    ØØ

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    JIT compiler is the workhorse . It takes the exe file loaded in memory and compiles it to native code . This is why it takes sometimes(well most of the time) too long for any .NET exe file to execute .My 2cents .

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: About compiling and running C# apps

    You can Ngen the assembly, in which case it is not JIT compiled - and you won't experience the lag on the first build.

    There are of course some drawbacks - none I deem critical or pertinent to most applications. In NoteMe's case, you could't Ngen a .Net assembly on Win platform and expect it to work on Linux (because its pre-compiled to native code).

    But you could copy the assembly over to Linux, and Ngen it there.

  10. #10

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: About compiling and running C# apps

    Sorry to be fool here, but what is NGen, and how do you do that?


    ØØ

  11. #11
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: About compiling and running C# apps

    ngen is a command line utility that comes with the SDK. It takes the IL from the assembly and compiles it to native code.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  12. #12

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: About compiling and running C# apps

    Thanks. Sounded like an buildt-in function in the IDE when he said it..



    ØØ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width