About hosting and non-hosting

Source: Internet
Author: User

From: http://blog.csdn.net/atlashr/archive/2009/05/06/4154387.aspx

What is managedCode? ouran highschool host club

Managed code is the Code Compiled by the Visual Basic. NET and C # compilers. The compiler compiles the code into an intermediate language (IL) instead of a machine code that can run directly on your computer. The intermediate language is encapsulated inProgramThe Assembly file contains all metadata describing the classes, methods, and attributes you have created (such as security requirements. This Assembly is an all-in-one shopping unit in the. NET world. You can copy the Assembly to another server to deploy it. Generally, this copy operation is the only operation in the deployment process.

The managed code runs in the Common Language Runtime Library (CLR. This Runtime Library provides various services for your running code. Generally, it loads and verifies the Assembly to ensure the correctness of the intermediate language. When some methods are called, The Runtime Library compiles the specific methods into a mechanical code suitable for the Local Computer to run, and then caches the compiled mechanical code for future calls. (This is instant compilation)alex trebek jeopardy host

As the Assembly runs, the Runtime Library continuously provides various services, such as security, harvest hosts memory management, and thread management. This program is "hosted" in the Runtime Library.

Visual Basic. NET and C # Can only generate hosted code. If you write programs in this type of language, the generated code is managed code. If you want to, Visual C ++. Net can generate managed code. When creating a project, select a project whose name starts with. managed. For example,. Managed C ++ application.

What is unmanaged code?

Unmanaged code is the Code created before Visual Studio. NET 2002 is released. For example, Visual Basic 6 and Visual C ++ 6. The worst thing is that, even the code generated by the old C compiler that is still residual in your hard disk and has more than 15 years of history is not managed. The managed code is directly compiled into the mechanical code of the target computer. These codes can only run on computers that compile and translate them, or on other computers with the same processor or almost the same processor. Unmanaged code cannot enjoy services provided by some runtime libraries, such as security and memory management. If the unmanaged code requires memory management and other services, it must explicitly call the interfaces of the operating system. Generally, they call the APIS provided by the Windows SDK for implementation. In recent cases, unmanaged programs use the COM interface to obtain operating system services.

And Other Visual Studio platformsProgramming LanguageDifferent,  jeopardy guest hosts ouran highschool host club Visual C ++ can create unmanaged programs. When you create a project and select a project whose name starts with MFC, ATL, or Win32, the project will generate an unmanaged program.

This will lead to some confusion: When you create a local c‑based program, it creates an intermediate language set and an executable file with an extension name of .exe. When you create an MFC program and create an executable file that is a Windows code, the extension name of this file is also .exe. The internal structures of these two files are completely different. You can use the intermediate language anti-assembler (ildasm) to view the internal and intermediate language metadata of the Assembly. If you try to use the intermediate language anti-assembler to view an unmanaged executable file, the modified anti-assembler will tell you that this executable file does not contain a legal CLR header, so it cannot be decompiled. The two files have the same extension, but they are completely different.

What is native code?hostos community college 

The phrase native code can be used in two different contexts. Many people think of native code as the same as unmanaged code: the code built with older tools deliberately uses Visual C ++ and enables it to run directly on a computer, it is not hosted in the Runtime Library. This can be a complete program, a COM component, hosta harvest hosts or a DLL file that can be called by hosted code using COM intero or platform call (pinvoke, com intero or platform call (pinvoke) can help you migrate to the new technical platform and reuse the two powerful tools of old code. I would like to say that the Code is not managed because it emphasizes the code that cannot take advantage of the services provided by the Runtime Library. For example, in managed code, code access security services can prevent code loaded on another server from running specific operations. If your code runs unmanaged code, you cannot use this protection service.

Another meaning of native code is to describe the output of the instant compiler,jeopardy guest hosts  the mechanical code that actually runs in the Runtime Library. These codes are managed codes, but not intermediate languages, but mechanical codes. Therefore, do not simply assume that native is equivalent to unmanaged.

Hosting code means hosting data?

For Visual Basic and C #, life is simple, the host hostos community college because you have no other options. When you declare a class in those languages, the instance of this class will be created in the managed heap, And the Garbage Collector (GC) will help us manage the collection of these objects. However, in Visual C ++, you have another option. Even if you are creating a managed program, you can decide which classes are managed and which classes are not managed.

This is an unmanaged type:alex trebek jeopardy host

Class foo
Int X;
Foo (): x (0 ){}
Foo (int xx): X (XX ){}

This is the hosting type

_ GC class bar
Int X;
Bar (): x (0 ){}
Bar (int xx): X (XX ){}

The only difference between them is that the bar class has the _ GC keyword. This keyword will bring a huge difference to the code.

Managed typeThey can be recycled by the garbage collector.It must be created with the keyword new, which will never appear in the stack.. The following line of code is valid:

Foo F;the host

However, this line of code is invalid:

Bar B;

If I create a foo object in the heap, I must be responsible for clearing this object:

Foo * pF = new Foo (2 );
Delete PF;

The C ++ compiler actually uses two heaps., A managed heap and an unmanaged heap. Then, the new operator is reloaded to create instances of different types and allocate different memory.

If I create a bar instance in the heap, I can ignore it. When no other code is using the class, the garbage collector automatically cleans up the class and releases the resources it occupies.

ForThe managed type has some constraints.: TheyMulti-inheritance is not allowedOr the inheritance or unmanaged type. They cannot use the friend keyword to implement private access, and they cannot implement copy constructor. Therefore, you may not want to declare your class as a managed type. But that doesn't mean you don't want your code to be hosted. In Visual C ++, you can select.

Hosting and unmanaged resources are part of C # and will not be discussed here.

Managed code and non-managed codePerformance Comparison 
Basically everyone knows that all. NET languages will be compiled into an intermediate language called Il assembly. However, many people do not know how the computer executes the intermediate code, or even understand it incorrectly.
JITIs an important part of. Net program running.Instant Compiler. The misunderstanding I just mentioned is that many people (definitely not a minority, I have asked many c ++ programmers, and there are 9 such ideas) JIT is actually something similar to Java VM. It is an interpreter that reads the Il assembly code at runtime and then simulates it into x86 code (also known as a virtual machine ). But in fact,. net uses more advanced technologies. After the. Net program is added to the memory, when a segment of IL code is run for the first time, the JIT compiler will compile the entire il code and then execute it. That's why the first time the. NET program was started slowly! With. net Library, Microsoft also comes with a tool, you can advance. all the Il code of the. NET program is compiled and stored in the cache. As a result, this program is exactly the same as that compiled by C ++, with no difference, the running time can also be separated from JIT (do not confuse it here, it is not to say that it can be separated. net Library, but does not need to be compiled in real time ). Therefore, do not confuse. NET and Java. The two operational efficiency is not a level at all!

JIT optimization refers to optimizing the local CPU during compilation. During compilation, traditional programs usually use the most common instruction sets (such as the ancient 386 Instruction Set) to compile to ensure compatibility. While JIT knows the specific type of CPU and can make full use of these additional instruction sets for compilation. This performance improvement is considerable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.