ASP.NET

Managed code and Unmanaged code in .NET

Managed code and Unmanaged code in .NET

Managed Code

A code written to aimed to get the services of the managed runtime environment execution like CLR(Common Language Runtime) in .NET Framework is known as Managed Code. Managed runtime environment provides different types of services like garbage collection, type checking, exception handling, bounds checking, memory allocation, type safety etc. to code automatically without the interference of the programmer. The application written in the languages like C#, VB.Net etc. are always aimed at runtime environment services to manage the execution and the code written in these types of languages are known as managed code.

CLR(Common Language Runtime)

In the case of .NET Framework, the compiler always compiles the manages code in the intermediate language(MSIL) and then create an executable. When the programmer runs the executable, then the Just In Time Compiler of CLR compiles the intermediate language in the native code which is specific to the underlying architecture.

Advantages

  • It improves the security of the application like when you use runtime environment, it automatically checks the memory buffers to guard against buffer overflow.
  • It implement the garbage collection automatically.
  • It also provides runtime type checking/dynamic type checking.
  • It also provides reference checking which means it checks whether the reference point to the valid object or not and also check they are not duplicate.

Disadvantages

The main disadvantage of managed language is that you are not allowed to allocate memory directly, or you cannot get the low-level access of the CPU architecture.

Unmanaged Code

A code that is directly executed by the operating system is known as Unmanaged code. It always aimed at the processor architecture and depends upon computer architecture. When this code is compiled it always tends to get a specific architecture and always runs on that platform, in other words, whenever you want to execute the same code for the different architecture you have to recompile that code again according to that architecture. It always compiles the native code that is specific to the architecture.

Advantages

  • It also provides direct access to the hardware.
  • It allows the programmer to bypass some parameters and restriction that are used by the managed code framework.

Disadvantages

  • It does not provide security to the application.
  • Due to the access to memory allocation the issues related to memory occur like memory buffer overflow, etc.
  • Error and exceptions are also handled by the programmer.
  • It does not focus on garbage collection.

Author: STEPS

Leave a Reply

Your email address will not be published. Required fields are marked *