Today, we will talk about Managed and Un-Managed code in .NET Runtime Environment. In previous tutorials we have seen how .NET code execution process is implemented.
Managed Code:
- In simple words, the code that is developed within .NET Framework or code whose execution is managed by CLR is termed as "Managed Code".
- Apart from Managed code execution, CLR also handles other responsibilities such as automatic memory management, run-time type checking, type safety.
- Managed code is a piece of code developed in high level programming languages such as C#, VB, F# run on top of .NET platform. When you compile the source code generated by these language compilers is converted in Intermediate language(IL) code. Machine code is generated by CLR by converting IL code.
- By using managed code, we avoid many typical programming errors which can lead to security bugs and flaws.
- C++ is one of the exceptions to the managed code execution process, as it produces unmanaged code that runs on Windows.
- Managed Code runs inside the Application Domain.
Un-Managed Code:
- The code which compiles directly to machine code and in-turn it is executed by OS is termed as "Un-Managed Code".
- It is targeted to specific architecture and it will only run under the executed platform. So, If anyone wants to run the Un-Managed Code on other environment it needs to be compiled under that platform.
- Un-Managed code consists like binary image which is directly loaded into memory. It results into faster code execution, but it is time consuming to rectify errors.
- Code compiled by legacy Borland C/C++ compilers, COM Components, ActiveX interfaces, and Win32 API functions are examples of Un-Managed Code.
- C# is only language that allows you to use unmanaged constructs such as pointers directly in code by utilizing what is known as unsafe context whose execution is not managed by CLR.
- Un-Managed Code runs as a process on Operating system.
No comments:
Post a Comment