ManagedCode(Managed code ): Code executed by the Common Language Runtime Library environment (rather than directly by the operating system. Managed code application Program You can obtain the Common Language Runtime library service, such as automatic garbage collection, runtime database type check, and security support. These services help provide unified managed code application behavior independent of platform and language.
Unmanaged code-unmanaged code : Code 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.
What is hosting and what is non-hosting?
Unmanaged code English name is
Unmanaged code , It is in
Public Language Runtime Library Environment Code that is directly executed by the operating system. The unmanaged code must provide its own services such as garbage collection, type check, and security support.
Managed code Different, the latter gets these services from the public Language Runtime Library.
What makes
Public Language Runtime Library Environment (English name is
Common Language Runtime . First, let's take a look.
Net Framework .
. NET Framework Is an internal Windows component that supports generating and running next-generation applications and XML Web Services.
. NET Framework There are two main components:
Public Language Runtime Library And
. NET Framework class library ( Framework class library
) .
Public Language Runtime Library Is the basis of. NET Framework. The runtime database can be viewed as a proxy for managing code during execution. It provides core services such as memory management, thread management, and remote processing, strict type security and other forms of code accuracy that can improve security and reliability are also enforced. In fact, the concept of code management is the basic principle of the Runtime Library.
Code targeting the Runtime Library is called managed code , And
Code that does not target the Runtime Library is called unmanaged code .. Another major component of the Net Framework is the class library, which is a comprehensive collection of reusable object-oriented Types and can be used to develop a variety of applications, these applications include traditional command line or graphical user interface (GUI) applications, and also include ASP-based. NET provides the latest innovative applications (such as web forms and XML Web Services ).
Then let's take a look at the execution process of the managed code:
1. Select the compiler:
To obtain the advantages of the Common Language Runtime Library, one or more language compilers must be used for the Runtime Library, such as Visual Basic, C #, Visual C ++, JScript, or one of many third-party compilers (such as Eiffel, Perl, or COBOL compiler.
Because the runtime is a multi-language execution environment, it supports various data types and language functions. The language compiler you use determines the available runtime functions, and you use these functions to design code. The syntax that must be used by the compiler (instead of the Runtime Library) to create code. If your component must be fully usable by components written in other languages, the export type of your component must only disclose the language functions included in the public language specification (CLS.
2. CompileSource codeTranslate to Microsoft intermediate language (msil) and generate the required metadata.
3. During execution, the real-time (JIT) compiler translates msil into local code. During this compilation process, the Code must pass the verification process, which checks the msil and metadata to see if the code can be identified as type-safe.
4. Run the code: the Common Language Runtime Library provides the structure of various services that enable execution and can be used during execution.