The unmanaged C/C ++ can be used in the underlying control system to precisely manage the memory as needed and easily create threads. VB6 allows you to quickly build UI applications and easily control COM objects and databases.
CLR is like its name. Runtime is used by many different programming languages. CLR feature is used for any CLR-oriented programming language. for example, runtime uses exceptions to report errors, so all languages report errors through exceptions. in another example, runtime allows you to create a thread, so all languages can create a thread.
In fact, during runtime, CLR does not know what programming language the developer uses, which means you should choose a programming language that is easier to express your purpose, as long as you use the CLR-oriented compiler.
So, if I say it is correct, what is better to use one language than the other? I think of the compiler as a syntax checker or code correction analyzer. They check your source code, make sure that the code you write is meaningful, and then output the code that expresses your will. different programming languages allow you to develop with different syntaxes. Do not underestimate the value of this choice. For mathematical or commercial applications, compared with Perl syntax, using the APL syntax to express your willingness can save a lot of time for development.
Microsoft has created several language compilers (for example, runtime): c ++/CLI, C #, VB, JScript, J #, and an intermediate language (IL) assembler. apart from Microsoft, some other companies have also created CLR-oriented compilers. I have noticed that the compilers include Ada, APL, caml, COBOL, Eiffel, forth, Fortran, Haskell, lexico, lisp, logo, Lua, mercury, ML, Mondrian, Oberon, Pascal, perl, PHP, Prolog, Python, RPG, scheme, smalltalk, Tcl/TK.
The process of compiling the original file shows that you can use any programming language that supports CLR to create the original file. Then you can use the corresponding compiler to check the syntax and analyze the source code. no matter what compiler you use, the compiled structure is a managed module. A hosted module is a standard 32-bit Microsoft Windows portable executable (pe32) file or standard 64-bit windows portable executable (pe32 +) file, which requires CLR to execute.
The following table describes each part of the managed module:
Parts |
Description |
Pe32 or pe32 + Header |
The standard Windows PE File Header, which is similar to the Common Object File Format (coff) header. if the pe32 format is used, the file will run on 32-bit or 64-bit windows. if the pe32 + format is used, the file needs to be run in 64-bit windows. this header also specifies the file type: Gui, Cui, or DLL. It also contains timestamp information to indicate the file build time. this information block is ignored for mudule that only contains il code. for modules that contain native CPU code, this header contains information about native CPU code. |
CLR Header |
Contains information that makes it a managed module. this header contains the required CLR version, some logos, The methoddef metadata symbol of the Entry Method (main method) of the hosting module, and matadata, resources, strong name, flag, the position/size of other less meaningful members. |
Metadata |
Each managed module contains a metadata table. There are two main types of tables: tables that describe the types and members in your source code, and tables that describe the types and members referenced in your source code. |
Il code |
The code generated by the compiler to compile the metacode. during runtime, the CLR will compile the Il as the native CPU instruction. |
Native code compilers generate code for specific CPU architectures, such as x86, x64, or IA64. all CLR-compatible compilers generate intermediate language (IL) code.Managed codeBecause the CLR manages its execution process.
In addition to generating Il, each CLR-oriented compiler must generate a complete metadata for each managed module. in short, metadata is a set of data tables that describe the content defined in the module, such as types and their members. in addition, metadata also includes the module references it manages, such as the Import Type and their members. metadata is a superset of the original technology (such as Type Library and Interface Definition Language IDL file. the important thing to note is that the information of CLR metadata is more complete. unlike the Type Library and IDL, metadata is always associated with files containing il code. in fact, metadata is always embedded into the same EXE/dll as the Code, making it difficult to separate it. because the compiler generates metedata and code at the same time and binds them to the final managed module, metadata and the Il code it describes never need to be synchronized with each other.
Metadata has many functions. Below are some of them:
- Metadata removes the header files and library files required for compilation, because all information about referenced types/members is contained in the files where Il is located (IL implements these types/members ). the compiler can directly read metadata from the managed module.
- Microsoft Visual Studio uses metadata to help you write code. Its SMART awareness feature parses metadata and tells you how a type provides methods, attributes, events, and fields. For a method, it tells you the parameters required by the method.
- The CLR code verification process uses metadata to ensure that your code only performs "safe" operations.
- Metadata allows the field of an object to be serialized into a memory block, sent to another machine, and then deserialized on a remote machine (deserialize ), status of the re-created object.
- Metadata allows the Garbage Collector to track the remaining time of an object. For any object, the garbage collector can determine the object type and determine which field of the object references other objects.
Microsoft's C #, VB, JScript, J # And il compilers always generate modules that contain hosted code (IL) and hosted data (garbage collection data type. end users must install CLR (currently. to execute modules that contain managed code and/or managed data. this is the same as the MFC class library or vB DLL required to run the MFC or VB6 application.
By default, Microsoft's c ++ compiler build EXE/DLL module only contains unmanaged code and data. these modules can be executed without the need for CLR. however, by specifying the/CLR command line switch, the C ++ compiler can generate a module containing hosted code. Of course, you must install CLR to execute the code. among all the Microsoft compilers mentioned above, C ++ is the most special, because it is the only compiler that allows developers to write both managed code and unmanaged code, and put them in a module. only Microsoft compilers can allow developers to define both managed data types and unmanaged Data Types in their source code. microsoft C ++ compilers provide far more flexibility than other compilers, because they allow developers to write applications with managed code and then access them in unmanaged C ++ code.