CLR via C #: CLR execution model

Source: Internet
Author: User
Tags hosting

 

 

1. CLR: runtime is a runtime that can be used by multiple programming languages"
  • Core CLR functions (such as memory management, assembly loading, security, exception handling, and thread synchronization) can be used in all CLR-oriented languages.
  • On this basis, compilers in different languages can be seen as syntax checkers and "correct code" analyzers.
  • No matter which compiler is selected, the result is a managed module (a standard executable file that can be transplanted, 32-bit or 64-bit, that is, a PE file, such as EXE, DLL, com, sys, etc)
2. Composition of the hosting module
  • PE Header: 32-bit can run on 32-bit and 64-bit systems, and 64-bit can only run on 64-bit systems, it also identifies the file type (including GUI, Cui, or DLL ).
  • CLR header: contains information that makes this module A managed Module
  • Metadata: including reference tables, definition tables, and list tables
  • Il code: the code generated when the compiler compiles the source code. During runtime, CLR compiles the Il CPU code at a cost (CPU-specific code)
3. Assembly: logical grouping of one or more modules/resource files. It is the minimum unit for reuse, security, and version control.
  • An assembly is also a PE file. An assembly can be either an executable application or a DLL (which contains a group of types used by executable programs)
  • Each Assembly contains a data block named "list". A list is another set composed of metadata tables.
  • The relationship between the Assembly and the hosting module can understand the relationship between components and atoms: a molecule is composed of one or more atoms, and a molecule is the smallest unit of a cell;
  • By default, the compiler will actually convert the generated managed module into an assembly.
4. Others
  • Il is irrelevant to cpu
  • The advanced language only discloses a subset of all CLR functions. However, the Il assembly language allows developers to access all CLR functions.
  • When executing a method, you must first convert its Il to a local CPU command. This is the responsibility of the clr jit compiler.
  • The clr jit compiler optimizes local code, which is similar to the work done by the unhosted C ++ compiler backend. JIT has a deeper understanding of the execution environment than the unmanaged compiler. It can generate any special commands that take full advantage of the local CPU support, which is conducive to improving the performance of local code. To counter this, an unmanaged application is usually compiled for a CPU with a minimal set of functions and does not use any special commands that can improve the performance of the application.
  • When you compile a local CPU command with Il, the CLR executes a verification process to ensure that everything the Code does is safe.
5. CTS: A general type system used for communication between different languages. After compiling different languages into il languages, there is a common type system, so they can communicate with each other. CTS rules: a type can contain zero or more Members. The members are as follows:
  • Field: a data variable, part of the object state. Distinguished by name and type
  • Method: A function can perform an operation on an object, which usually changes the object state.
  • Attribute: for callers, it looks like a field; for Type implementers, it looks more like a method
  • Event: A notification mechanism is implemented between objects and other related objects.
CTS also defines rules for the type of Accessability (private, protected (family), public, assembly (internal), type inheritance, virtual methods, object lifetime, and so on. Different languages are used, and the syntax for defining types is also different. However, no matter which language is used, type behavior is completely consistent, in the end, Clr and CTS are used to define the type of behavior. 6. CLS: A Public language specification that defines a minimum set of functions. Any compiler-generated type must support this minimal feature set to be compatible with components generated by other "CLS-compliant and CLR-oriented languages. CLS rules: In CLR, each member of a type is either a field (data) or a method (behavior ). What attributes, indexes, delegation, events, constructors, Operator overloading, and arrays are encountered by the compiler in the source code (these are additional abstractions provided by the language to facilitate programming ), at the Il level, fields and methods must be converted. 7. CTS and CLS:
  • If developers use the Il assembly language to write programs, all the functions provided by CTS can be used.
  • Most languages (such as C # and VB) only provide a subset of CTS functions.
  • CLS defines a minimum set of functions that must be supported by all CLR-oriented languages.
  • When defining a type in one language, if you want to use this type in another language, do not use any function outside CLS in public and protected members of this type, this feature may not be supported in other languages.
 

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.