CLR via C # 3 reading notes (1): CLR execution model in Chapter 1 – 1.1 Compile the source code for the managed module
CLR the name suggests, refers to a variety of different programming languages can be used runtime. CLR can be used for all the core features of the programming language for it. For example, run-time errors using exceptions to report, all the language-oriented run-time exception to get through the error report. Another example, also allows the creation of threads running, all the language-oriented run-time thread can also be created.
At runtime, CLR language used on the developer to complete the source code for nothing. We can choose any language to write code, as long as the compiler can compile code for the CLR.
How to select language? Authors believe that the compiler is a grammar checker, and “correct code” of the analyzer, which checks source code, make sure you write a meaningful and describe your intended output of the code. Different languages have different syntax. For different purposes, you can choose a different language. Can significantly reduce the amount of code.
Microsoft has created a language for the CLR compiler: C + + / CLI, C #, Visual Basic, F #, IronPython, IronRuby, and an intermediate language assembler (Intermediate Language Assembler).
The following diagram shows the process of compiling the source code files. As shown, we can use any CLR language to write the source code file, then the compiler will check the appropriate syntax, and analyze the source code. Regardless of the compiler, the final results are managed module (Managed Module). CLR managed module is a need to be able to perform the standard 32-bit Microsoft Windows portable executable (PE32) file, or standard 64-bit Windows Portable Executable (PE32 +) files.
The composition of managed module
PE32 or PE32 + header: standard PE file header, similar to the Common Object File Format head. If the first use of PE32 format, the file can be run on 32-bit or 64-bit Windows which. If the header using the PE32 + format, the file must run them on 64-bit Windows. The head is also the type of the file named: GUI, CUI, or DLL, and also to specify the file contains a time stamp when created. IL code for the module that contains only, PE32 (+) in the amount of information will be ignored. Contains the code for the local CPU module, the first code also includes information on the local CPU.
CLR header: identify the managed module that contains some information (CLR or some tools that can be resolved). Including managed module required CLR version number, number of tags managed module entry point method (main method) MethodDef metadata tagging, and metadata related to managed module (metadata), resources (resources), strong named (strong name) , mark (flags), and other information is not meaningful location and size.
Metadata: Each module contains a number of managed meta data tables. Metadata table is divided into two types: one defined in the code used to describe the types and members. A reference code used to describe the types and members.
IL code: the compiler source code generated code. At runtime, CLR will compile the IL to the local CPU instruction.
Most of the early compiler-generated code is for a specific CPU architecture. All CLR-compliant compiler is generated IL code. IL code, also known as managed code (managed code), because the CLR to manage their implementation.
In addition to generating IL, each compiler for CLR requires that all managed module also generates a complete metadata. In short, metadata is a set of data tables, the data table has a number defined by the description of the content managed module (such as the definition of the types and their members), in addition to some descriptive content referenced managed module (such as reference types and their members.) Metadata is some of the early technologies, such as COM type libraries and IDL (Interface Definition Language) files superset. Should be noted that, CLR metadata than they are to complete. And IDL and type libraries, and the difference is, metadata is always the file that contains code associated IL. Metadata is always a matter of fact, and the code (IL code?) With embedded in the same EXE / DLL file, the two are inseparable. Because the compiler while generating metadata and IL code, and bind them to build a managed module, hence the description of metadata and IL code always maintained between the synchronization.
The use of metadata
Compile-time metadata no longer need to make the local C / C + + header files and library files, it is because to achieve the type containing the members of the IL code and files, have been cited include the types and members of the information. Compiler can be read directly from the managed module metadata.
Visual Studio uses the metadata to help us write code. IntelliSense feature by parsing the meta data to tell us the type provided by the methods, properties, events, and fields, and the method parameters.
CLR code verification process to ensure that the code uses the metadata to perform only “type-safe” operation.
Metadata field of an object can be serialized to the memory block, passed to another computer, and then deserialize, and the remote computer to re-create the object state.
GC tracking objects using metadata life cycle. For any object, GC can be obtained from the metadata of its type, and which fields refer to other objects.
For more detailed metadata, content, in Chapter 2.
C #, VB.NET, F # and the compiler always generated IL contains managed code (IL), and managed data (GC data type) modules. These include end-user to perform managed code and managed data module, you must install the CLR (currently used as. NET Framework as part of release). This MFC or VB6 applications to run must be installed and the VB DLLs MFC library is the same reason.
By default, C + + compiler is included unmanaged (native) code of the EXE / DLL module, in the run-time operation of a non-managed data (local memory). Implementation of these modules do not need to CLR. However, if you specify / CLR command-line options, C + + compiler will generate the module contains managed code, and the execution environment must also install the CLR. C + + is the only allowed developers to write managed and unmanaged code and generate the same module in the compiler. This allows developers to use managed code in non-managed code.
Sorry, the comment form is closed at this time.