1. What is the managed code in C?
A: managed code is actually an intermediate language (IL) code. After the code is compiled, the compiler compiles the code into an intermediate language (IL) instead of a machine code that can run directly on your computer. The Assembly file encapsulates the intermediate language, which contains all metadata describing the created methods, classes, and attributes. The managed code runs in the Common Language Runtime Library (CLR. This Runtime Library provides multiple services for Running code. Generally, the Common Language Runtime Library can load and verify the Assembly to ensure the correctness of the intermediate language. When some methods are called, the Common Language Runtime Library compiles the specific methods into machine codes suitable for running on local computers and caches the compiled machine codes for use in the next call. This process is instant compilation.
Note: The program is actually "hosted" in the Public Language Runtime Library. As the Assembly runs, the Common Language Runtime Library continuously provides various services, such as memory management, security management, and thread management.
Summary:
Managed code is the code executed by the Common Language Runtime Library (CLR), rather than directly executed by the operating system.
Managed code can also call the CLR Runtime library services and functions, such as GC, type check, and security support. These services and functions provide independent and unified management with development languages
Code Application behavior.
2. What is the unmanaged code in C?
A: unmanagedcode refers to the machine code that is directly compiled into the target computer. The unmanaged code can only run on the computer that compiled the code, or on other computers with the same processor or almost the same processor. Unmanaged code does not support services provided by the Common Language Runtime Library, such as memory management and security management. If the unmanaged code requires memory management and other services, it must explicitly call the interface of the operating system. Generally, the unmanaged code calls the API provided by windowssdk to implement memory management. An unmanaged program can also call the COM interface to obtain operating system services.
Note: C # is different from other programming languages on the Visual Studio platform. C # can create hosted and non-hosted programs. If you select a project whose name starts with MFC, ATL, or Win32, the project will generate an unmanaged program.
Summary:
Unmanagedcode is the Code directly executed by the operating system rather than the CLR Common Language Runtime Library.
Unmanaged code must provide such services as garbage collection, type check, and security support.