Common Language Runtime

Source: Internet
Author: User


What is the CLR?
The code that runs in the. NET framework last time is called managed, and vice versa is called unmanaged code. There are many benefits to unmanaged code,managed code, such as writing in multiple programming languages, improving security, easy versioning, and program publishing. These are provided by the CLR. But there are some disadvantages, the most easy to think of is the speed of the code to run the problem.

To provide the above functionality for managed code, the CLR must know the type of data in the code, the class, and the definition of the assembly associated with her. This information is called metadata, and metadata is included in some part of the code (compiled). The CLR uses this metadata to load code snippets, manage memory, execute method calls, and so on.

. NET before, it is impossible to share the original code between different programming languages. Because each programming language defines a different data type, and the syntax is different. Microsoft Masters think of a good way to unify data types. This technique is called CTS (common type System). Now do project development is relatively simple (in different languages), such as a project team will use VB, will use C + +. Perhaps the previous approach was to write a function of two people calling each other as DLLs or COM. But now it's not so much trouble, you can use code written in other languages directly. Specifically, you can inherit C + + with vb.net. NET Write class, the converse is also OK.

When we install the software, we often come across the hint that the components in the system are newer than the components to be installed, do you want to replace or retain them? Is it annoying?! Now you start with. NET, she won't bother you because of this "little" problem. Because each code contains a METADATA,CLR associated with her, it manages different versions of the code based on this information. And because you don't have to register the code information in the registry, you can install the code in a x-copy way (simply copy and paste it).

Is using VB to do it well? Or do you do it in C + +? These are the problems that we often have to consider when we do the project. But in. What programming language net has become unimportant (but still somewhat different in a particular project), because the CLR provides the CTS (and the base Class library), and it all runs on the CLR. Languages such as vb,c++ in. NET have been considerably improved and have new language C #. C # has applied for the standard and passed, imagine her powe. As you know, Borland also released the relevant development tools C # Builder.

Make a summary.

1,. NET code contains information related to yourself called metadata.

2. The CLR provides CTS (the CLS also has credit), so it is possible to share the original code between different programming languages.

3, with metadata management code information (not using the registry), so the code is easy to install.

4, the use of unified data types and class libraries, so the choice of programming language becomes unimportant, and easy to team development.

The process of code running in the CLR

1. Select compiler

First the CLR chooses the compiler, because code developed in different languages can be run in the CLR.

2. Compile the code into MSIL

The CLR uses the selected compiler to generate MSIL (Microsoft intermediate language) and metadata to load them into PE (portable executable file).

MSIL: An interpretation language that contains code information that makes JIT easy to compile into machine language. Independent of the operating system and programming language.

PE: Executable file format, Windows is a DLL or EXE.

3. Using JIT compiler to compile MSIL into machine language

There are two ways to compile only the currently executing code snippet, and the other is to compile the entire code one at a time. The JIT detects the security of the code.

4. Execute code

The first call to code is compiled into machine code and is no longer recompiled when it is called again.

Related tools

-msil Generator-MSIL assembler (Ilasm.exe)

-msil anti-compiler-MSIL assembler (Ildasm.exe)

Use method

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpconmsilassemblerilasmexe.asp

Related information

-PE structure

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconmetadatapefilestructure.asp

Resources

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsourcecodelanguage.asp




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.