.NET Framework Common Language Runtime

zhaozj2021-02-16  50

.NET Framework Common Language Runtime

What is the CLR?

Last time, the code running in the .NET Framework is called Managed Code, and it is called unmanaged code. Compared to Unmanaged Code, Managed Code has a lot of benefits, such as multi-programming language, improve security, easy version control, and program publishing, and more. These are provided by the CLR. But there are also some unfavorable points, the easiest thing to think is that the code running speed problem.

To provide the above features for Managed Code, the CLR must know the data type in the code, the classes, and the definition of Assembly with her associated. This information is called Metadata, and Metadata is included in some part of the code (after compiling). CLR uses this Metadata loading code segment, manages memory, execute method calls, etc.

.NET comes before, sharing the original code between different programming languages, is simply impossible. Because each programming language definition is different, the syntax is different. Microsoft masters thought of a good way to uniform data types. This technology is CTS (Common Type System). Now doing project development is relatively simple (in different languages), such as using VB in a project group, use C . Possible methods are written to DLL or COM with functions that are called between two people. But now you don't have to trouble so, you can use the code written in other languages ​​directly. Specifically, use VB.NET to inherit C . Net written, which is also possible.

We often encounter such a prompt when we install software - the components in the system are new, do you want to replace or reserve more than the components to be installed? Is it very annoying? ! Now you start with .Net, she will not bother you because of this "small" problem. Because each code contains Metadata associated with her, the CLR will manage the different versions of the code based on this information. And because you don't have to register the code information to the registry, you can install the code in the way in X-COPY (that is, a simple copy paste).

Is it done with VB? Still do it with C ? These issues are the problems that we often consider when we do projects. But in what programming language in .NET has become unimportant (but there is still a certain difference, in a specific project), because the CLR provides CTS (and Base Class Library), and all runs on the CLR. There is a quite increase in languages ​​such as VB, C in .NET, and have new language C #. C # has applied for a standard and passed, and it is conceivable to know her POWE. Everyone knows that Borland also released the related development tool C # Builder.

Make a small knot

n .NET code contains information related to yourself called Metadata.

N CLR provides CTS (CLS also has credit), so you can share the original code between different programming languages.

n Use metadata management code information (not using registry), so code is easy to install.

n Use a unified data type and class library, so the selection of programming languages ​​is not important, and it is easy to develop.

Running process of code in CLR

n Select Compiler

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

N compiles the code into msil

The CLR generates MSIL (Microsoft Intermediate Language) and Metadata to generate MSIL (Portable Executable file) with the selected compiler. MSIL: Interpret language, contain code information, let JIT easy to compile into machine language. Unrelated to the operating system and programming language.

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

n Compile MSIL into a machine language with a JIT compiler

There are two ways to compile the currently executed code segment, and the other is to compile the entire code one-time. JIT will detect the security of the code.

n Execute code

The code first call will be compiled into a machine code. When you call it again, it will not be recompiled.

Related tools

-Msil generator - MSIL Assembler (Ilasm.exe)

-Msil anti-compiler - MSIL Assembler (Ildasm.exe)

Usage

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

Relevant information

-PE structure

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

Reference

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

转载请注明原文地址:https://www.9cbs.com/read-22859.html

New Post(0)