Difference Between Managed and Unmanaged Code in .NET

Learn: What are the differences between managed and un-managed code in .Net? How you can write a managed code in .Net technology (using supported languages)?
[Last updated : March 26, 2023]

In this post, we are going to learn the differences between managed and un-managed code in .Net and how we can identify which whether a code is managed or un-managed?

Managed Vs Unmanaged Code

There are following point that clears the difference between managed and un-managed code:

  1. Managed code is the code which is executed by Common Language Runtime instead of operating system. While Un-managed code is the code which is executed directly by the operating system outside the Common Language Runtime environment.
  2. The managed code compiler first compiles the manage code to MSIL code, also known as CIL code. This MSIL code doesn’t depend on any machine configuration and we can execute it on different machines. The un-managed code is directly compiled to native or machine code which depends on the machine configuration.
  3. In managed code, execution of the code handled by CLR, CLR provides different services like garbage collection, exception handling, security support and type checking. Whereas in case of un-managed code allocation and de-allocation of memory and type safety to be taken care of by the software developer.
  4. If the un-managed code is not properly handled, it may result in memory holes or memory leaks.
  5. Examples of un-managed code are Win32 APIs and ActiveX components that are execute beyond the scope of common language runtime.

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.