. The CTS, CLS, and CLR in net

Source: Internet
Author: User

  Explanation of MSDN:the. NET Framework is a managed execution environment that provides a variety of services for the applications it runs. It includes two main components: the common language Runtime (CLR) as the execution engine for processing running applications, and the. NET Framework class Library, which provides a tested reusable code base that developers can invoke from their own applications.

  The CLR is at the heart of the. NET Framework

The core of the CLR is the CTS and the CLS. In any programming language, if you want to execute on the. NET CLR, you must provide a compiler that compiles the program for that language into the metadata and IL that the. NET CLR knows, and conforms to the CTS rules.
CTS is a common type system (Common type systems)
CLS is a common language definition (Common Language specification)
CLR is the common language runtime (Common language runtime)

  

In any programming language, if you want to execute on the. NET CLR, you must provide a compiler that compiles the program for that language into the metadata and IL that the. NET CLR knows, and conforms to the CTS rules. Not all languages are as consistent with the CTS specification as C #, after all, many languages appear earlier, and CTS appears behind, so there are some older languages that fail to conform to the CTS rules. This kind of language is in. NET has the following three ways to conform to the CTS specification:

-Change the language itself to comply with the CTS rules. For example, Visual Basic 6 has made a significant expansion and change, plus inherited features, which makes the new version of Visual Basic. NET almost a whole new language, as if C had been derived from the same year.

-The extension language itself is close to the CTS, but retains the syntax incompatible with the CTS, so that the CTS-compliant process is compiled in the same way that it does not conform to the CTS rules and is compiled into native code in the traditional manner. This is true for example, C + + with Managed Extension (abbreviated as mc++).

-The language itself is as constant as possible, and everything is achieved through a strong compiler design that is compatible with the CTS, Eiffel. For example, the CTS does not support multiple inheritance (multiple inheritance), but Eiffel supports multiple inheritance, and the Eiffel compiler can use interface and attribute to achieve multiple inheritance (this is quite ingenious, Interested readers may wish to look into it.)

OK, now let's look at the relationship between the three of them.


  1) CTS Universal type System (Common type systems)

The CTS defines the rules that a set of language compilers must follow to define, reference, use, and store reference types and value types. Therefore, by following the CTS, objects written in different languages can interact with each other. But not all types can be used in all languages.

The CTS not only implements the variable compatibility type of COM, but also defines the type extension by means of user-defined types. Any to. NET platform as the target language must establish a mapping between its data type and the type of the CTS. All. NET language to share this type of system, to achieve seamless interoperability between them. The scheme also provides the inheritance between languages. For example, a user can derive a class written by C # in vb.net. We can think of CTS as the Superset (union) of all. NET languages, and the various languages that conform to CTS are actually just subset (intersection) of the CTS. The programs written by these languages, if you want to have the best compatibility to invoke each other (invoke) or inheritance, these languages must obtain a common subset, there is a common adherence to the specification, this is the CLS.


  2) CLS Common Language Specification (Common Language specification)

The CLR integrates many languages, and they can be accessed from one another because of the standard set of types, metadata, and public execution environments that the CLR establishes. Because of the great differences between languages, such as case sensitivity, some methods that do not support unsigned, operator overloading, or variable parameters, to create a program that can be accessed by other languages, the programming language you use can only use those features that are supported in other languages. To help us do this better, Microsoft has defined a "Common Language Specification (Common Language specification,cls)"

Obviously, the difference between programming languages is not just the type. For example, some languages support multiple inheritance, some languages support unsigned data types, and some languages support operator overloading. Users should be aware of this, therefore. NET limits the interoperability issues raised by these differences by defining common language Specifications (Cls:common Language specification). The CLS has developed a minimal feature that must be supported by a language that targets the. NET platform, as well as the complete characteristics required for interoperability between the language and other. NET languages. Recognizing that this is important, the characteristic issues discussed here are not just simple grammatical differences between languages. For example, the CLS does not care about what keywords a language implements for inheritance, but only about how the language supports inheritance. The CLS is a subset of the CTS. This means that a language feature may conform to the CTS standard, but is beyond the scope of the CLS. For example, C # supports unsigned numeric types, which can pass the CTS test, but the CLS only recognizes symbolic numeric types. Therefore, if a user uses a C # unsigned type in a component, it may not be designed with languages that do not use unsigned types, such as vb.net. NET components for interoperability.

  3) CLR Common language Runtime (Common Language Runtime)

To put it simply, the CLR is the implementation of the CTS, which means that the CLR is the application's execution engine and a fully functional class library, which is implemented in strict accordance with the CTS specification. As a program execution engine, the CLR is responsible for securely loading and running user program code, including garbage collection and security checks on unused objects. Code that runs under CLR monitoring, called Managed code (managed).

  Execution model of the CLR

  1. Compile the source code (VB, CS) into a managed block of code. Managed code blocks are composed of intermediate languages and meta data.

2. Merge managed code into an assembly, also called a component (DLL). The assembly contains a module called "manifests" that records the information that makes up the assembly module, including the resource file and the information that needs to be referenced.
3. Load the common language runtime.
4. Execute code for the assembly.
5. Generate local code (unmanaged code).

execution model of the CLR

  

Language complier: Language compiler, each language based on. NET language will have a CLR-oriented managed module, or can be understood as a language compiler, the corresponding language compiled into MSIL
MSIL: Microsoft intermediate Language, the CLR is responsible for the intermediate language compiled into the computer to execute the program can understand the language, is a high-level language and assembly languages in the pseudo-assembly.
JIT (Just in-time Compile): Instant compilation, which interprets MSIL as a language that the program can understand.

. The CTS, CLS, and CLR in net

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.