Skip to content

Managed and unmanaged code

amit_gupta14

Asked Mar 29, 2006, 9:29 PM EST2 answers
Share
LinkedInX

Each .NET language has its own complier. when we write a code in C#, C# complier converts it into MSIL. Then JIT converts this code into machine dependent code.

My question is:
IF we write a code in any .NET language, is it managed code?
IF we do not write a code in any .NET language, is it unmanaged code?

What's difference/usage of two?

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    C# is managed code, in general you can write unmanaged code by using the "unsafe" keyword. To be managed means that you(the programmer) isnt managing the memory yourself. Like in C/C++ you call malloc or new and you can have pointers flying everywhere you have a much greater chance of causing a memory error.
    0
  • 0

    All .net languages target the CLR(common language runtime), and produces IL (Interndiate Language). This along with the Metadata goes into your PE (portable executable). Now what makes this "Managed Code" is the fact that the .Net Runtime manages the execution of this code. When the code is run, your IL is compiled JIT to native code by a runtime aware compiler. And at this point, the managed execution environment handles your memory management/garbage collection, type safety, overflow/boudary checking, index checking etc.
    Unmanaged code (say regular c code) is just a piece of binary code loaded into memory, OS handles memory management to a certain level, but dont have any other control on what your code does and how it does!

    Cheers!

    0