Difference between Managed and Unmanaged code in .NET


.NET Framework has CLR, Common Language Runtime which execute the code written in .NET languages. CLR manages the memory needs, security concern, code optimization, platform specific conversion etc. In case of Unmanaged code, no CLR is present, and code is directly executed by Operating system.

Following are some of the important differences between Managed and Unmanaged code.

Sr. No.KeyManaged CodeUnmanaged code
1Executed ByExecuted by CLR, Common Language Runtime, also named as Managed Runtime Environment.Executed by Operating System directly on the underlying hardware.
2SecurityCLR handles security concerns and provides inbuilt security to code written in .NET.No inbuilt security present. It is developer's responsibility to write safe and secure code.
3Memory OverflowMemory buffer overflow never happens, as CLR handles memory allocation and deallocation automatically.Memory buffer overflow can occur and can hamper the program execution badly.
4Runtime ServicesCLR provides automatic garbage collection, exception handling to managed code.No automatic garbage collection and other services are provided to unmanaged code.
5OutputManaged Code is converted to IL, Intermiddiate Language also termed as CIL of MSIL.Unmanaged Code is converted to native language code.
6Low Level AccessProgrammer has no low level access using Managed Code.Programmer can write low level access code using unmanaged code.

Updated on: 06-Jan-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements