Open In App

Difference between Managed and Unmanaged code in .NET

Improve
Improve
Like Article
Like
Save
Share
Report

Managed code is the code which is managed by the CLR(Common Language Runtime) in .NET Framework. Whereas the Unmanaged code is the code which is directly executed by the operating system. Below are some important differences between the Managed code and Unmanaged code: 

Managed Code

Unmanaged Code

It is executed by managed runtime environment or managed by the CLR. It is executed directly by the operating system.
It provides security to the application written in .NET Framework. It does not provide any security to the application.
Memory buffer overflow does not occur. Memory buffer overflow may occur.
It provide runtime services like Garbage Collection, exception handling, etc. It does not provide runtime services like Garbage Collection, exception handling, etc.
The source code is compiled in the intermediate language known as IL or MSIL or CIL. The source code directly compiles into native languages.
It does not provide low-level access to the programmer. It provide low-level access to the programmer.
Memory is managed by CLR’s Garbage Collector. Memory is managed by the programmer.
Performance is Slightly slower due to the overhead of memory management and JIT compilation. Performance is Faster due to direct access to system resources and compiled machine-specific code.
Debugging is easier due to the availability of CLR’s debugging tools. Debugging is harder due to lack of debugging tools.
Managed code requires installation of CLR on the target machine Unmanaged code Can be distributed as a standalone executable or DLL file.
Interoperates well with other .NET languages and libraries. Limited interoperability with .NET languages .
Runs on any platform that has CLR installed. Runs only on the specific platform for which it is .

 

 


Last Updated : 16 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads