C # understanding of managed code and unmanaged code,
To understand managed and unmanaged code, you must first understand CLR (Common Language Runtime Library)
. Net Framework is composed of two independent and related parts: CLR and class library. CLR is the service it provides for us, and class library is the function it implements.
Most of. NET's features-garbage collection, version control, thread management, and so on, all use the services provided by CLR.
When you are. when the NET Framework compiles the source code, the target code is not a machine instruction that the CPU can recognize, but a kind of code called "Microsoft intermediate language (MSIL, or IL for short). CLR provides a real-time compiler,
It is used to compile the IL code into the local machine code. in this way, the CLR can make the code portable, because. NET application source code must be compiled into IL code, which can run on any platform that provides CLR services. from the perspective of CLR,
All languages are equal, as long as there is a compiler that can generate IL code, this ensures the interoperability of various languages.
Managed code-managed code
Code executed by the Common Language Runtime Library (CLR) Environment (rather than directly by the operating system. Hosted code applications can obtain the Common Language Runtime library service, such as automatic garbage collection, Runtime Library type check, and security support.
These services help provide unified managed code application behavior independent of platform and language.
Unmanaged Code-Unmanaged Code
Code that is directly executed by the operating system outside the public Language Runtime Library environment. The unmanaged code must provide its own services such as garbage collection, type check, and security support. Unlike the hosted code, the latter obtains these services from the public Language Runtime Library.