When working with .NET Framework, you will often encounter the term "managed code". This document will explain what this term means and additional information around it.
To put it very simply, managed code is just that: code whose execution is managed by a runtime. In this case, the runtime in question is called the Common Language Runtime or CLR, regardless of the implementation (Mono or .NET Framework or .NET Core). CLR is in charge of taking the managed code, compiling it into machine code and then executing it. On top of that, runtime provides several important services such as automatic memory management, security boundaries, type safety etc.
Contrast this to the way you would run a C/C++ program, also called "unmanaged code". In the unmanaged world, the programmer is in charge of pretty much everything. The actual program is, essentially, a binary that the operating system (OS) loads into memory and starts. Everything else, from memory management to security considerations are a burden of the programmer.
Managed code is written in one of the high-level languages that can be run on top of .NET, such as C#, Visual Basic, F# and others. When you compile code written in those languages with their respective compiler, you don’t get machine code. You get Intermediate Language code which the runtime then compiles and executes. C++ is the one exception to this rule, as it can also produce native, unmanaged binaries that run on Windows.
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 complied in the intermideate language know as IL or MSIL or CIL. | The source code direclty compile into native langugae. |
It does not provide low-level access to the prgrammer. | It provide low-level access to the prgrammer. |
No comments:
Post a Comment