First glance at. NET Framework (original)

Source: Internet
Author: User

1. Introduction to. NET Framework
. NET Framework for application developmentProgramAnd a revolutionary platform .. . NET framework can be used to create Windows applications, web applications, web services, and other types of applications .. . NET Framework .. Net Framework is an underlying framework, including developers writing, generating, testing, and deploying. NET framework is used to facilitate developers to write network applications and Web Service programs. A key feature of net framework is that it provides a development and execution environment for multilingual components.
. NET Framework mainly contains a very largeCodeLibrary. This library is divided into different modules, so that you can choose to use each part of the library based on the expected results. The objective is that different operating systems can support some or all of these modules based on their own features.
The. NET Framework class library is a set of reusable classes. In terms of position, the. NET Framework introduction is the "Operating System" of all development languages and is a basis.


2. Organizational structure of the Framework
. NET Framework Introduction mainly includes common langue Runtime (CLR), Class Library, and assembly.
Public Language Runtime
The Common Language Runtime is an engine that executes and manages Code. The Code is compiled in real time. During code execution, CLR provides garbage collection for memory management, enhanced security, and interoperability with controlled code.
Class Library
A class library is a set of reusable classes in the framework, including type security, hierarchical security, and internal trust mechanisms.
Assembly
Libraries used by other applications (whose extension is. dll ). An assembly is a logical unit of code that contains compiled and oriented. NET Framework. The Assembly is completely self-descriptive and can be stored in multiple files. An important feature of an assembly is that the data they contain describes the types and methods defined in the corresponding code, and the Assembly also contains metadata that describes the Assembly itself, this type of assembly metadata is contained in an area that becomes an assembly list and can check the version and integrity of the Assembly. The metadata of the Assembly inclusion program indicates that the application that calls the code in the given assembly or other assembly does not need to specify the registry or other data sources. All metadata is stored together with executable commands of the program. Files that contain the Assembly entry also store the details, hashes, and content of other files.
In addition to msil, an assembly also contains metadata and optional resources (other data used by msil, such as audio files and images ). Metadata allows the assembly to be completely self-described. you can use an assembly without additional information. therefore, deploying an application is very simple. You only need to copy the file to the directory on the remote computer. because no other information on the target system is required, you only need to run the executable file from this directory (assuming that the file is installed. netclr ).
Of course, you do not need to install all the information required to run the application in one place. You can write some code to execute the tasks required by multiple applications, in this case, the code is usually stored in a place that can be accessed by all applications. in. in the. NET Framework, This is the Global Assembly Cache (GAC). It is very easy to put the code in this cache, you only need to put the Assembly containing the Code in the directory containing the cache of the high-speed program.


3. Use. NET Framework to write applications
To execute C # code, you must convert it into a language that can be understood by the target operating system, that is, the local code. This type of conversion is to compile code, which can be performed by a compiler. net Framework:
SetSource codeCompile to msil
Compile msil into machine-recognized assembly code.
Whether it is a development language, it must be compiled into an intermediate language that can be recognized by the framework. This is a key technology that CLR can support multi-language development.


4. msil
When compiling code that uses the. NET Framework library, instead of creating the operating system-specific local code immediately, the code is compiled into Microsoft intermediate language (msil ). This code is not designed for any operating system. Msil code is independent of machines, operating systems, and CPUs. MISL is a low-level language. The syntax simply uses digital code instead of text code, which can be quickly converted to internal machine code.
Main features of intermediate language:
Object-oriented and user interfaces: single inheritance.
Different value type and reference type: the value type variable saves its data. The reference type variable only saves the address, and the corresponding data can be found in this address.
Strong data type: all variables are clearly marked as belong to a specific data type. In particular, the intermediate language generally does not allow any operation on the Fuzzy data type. If a class is derived from another class or an instance that contains other classes, it needs to wait until all data types used by other classes .. NET provides the following benefits: language interoperability, garbage collection, security, and application domain.
Feature usage: You can use this mechanism to define your own features in the source code. These user-defined features are incorporated into the data of application data types or methods, which is useful in the documentation. Features and reflection technologies are used together to execute programming tasks based on features.


5. General Type System
The. NET Framework library defines some basic types. A data type is a data expression that specifies the most basic part for use. net Framework performs interactive operations between various languages. This is called the Common Type System (CTS ). CTS solves the problem of strong data types in language interoperability.


6. Common langue specification (CLS)
The common language specification CLS ensures language interoperability with the common type system CTS. CLS is a minimum standard and must be supported by all. Net-oriented compilers.


7. Garbage Collection
An important function of code hosting is garbage collection (GC ). This. Net method ensures that the memory will be completely released when the application no longer uses some memory .. The method used by the net Runtime Library is the garbage collector. The specific method is that the memory of all dynamic requests is allocated to the heap (CLR maintains its own managed heap). When cleaning is required, the spam collector is called. The garbage collector processes all variables in the current Code, checks references to objects stored on the managed stack, and determines which objects can be accessed in the code, that is, which objects have references, objects that are not referenced cannot be accessed from the Code and thus deleted.


8. security
. net complements the security mechanism provided by windows, because it provides code-based security, while windows only provides role-based security. Role-based security is based on the identity of the account that runs the process. In other words, it is who owns and who runs the process. Code-based security is based on the credibility of the tasks and codes actually executed by the Code

.
9. application domain
the application domain is. net, which is used to reduce the system overhead of running applications. These applications need to be separated from other programs, but still need to communicate with each other. Isolated Code can be implemented through processes. When running a new application, it runs in a process environment. In Windows, processes are separated by address space, so that each process has 4 GB of virtual space, windows uses an additional indirect method to map these virtual memory to a special area of physical memory or disk space. Each process has a different ing, the physical memory mapped to the virtual address space cannot overlap. Generally, any process can only access the memory by specifying an address in the virtual memory. That is, the process cannot directly access the physical memory. Therefore, one process cannot access the memory allocated to another process, in this way, any code that fails to be executed will not damage data other than its address space.
however, five or more processes often work together and need to communicate with each other. Because the process cannot share the memory, a complicated grouping process needs to replicate data between processes, which has a great impact on the performance.
application domains are a way to separate components. It does not cause performance problems caused by data transmission between processes. By decomposing any process into multiple application domains, each application domain corresponds to an application, each thread that is executed runs in a specific application domain. If different executable files run in the same process space, they can easily share data because theoretically they can directly access each other's data. CLR checks the code of each running application domain to ensure that the Code does not deviate from its own data zone. How can I tell the program what to do without actually running it? Interlanguage has powerful type security functions. Generally, unless security features are not explicitly used, the data type used ensures that the memory is not accessed incorrectly. To run an application, you must call the. NET remote service to communicate or share data with other applications running in different application domains.

10.jit< br> just-in-time compiles msil into local code dedicated to the operating system and the target machine structure so that the operating system can execute applications.
11. managed Code
after the code is compiled into msil and compiled into local code using the JIT compiler, the CLR tasks are not completed yet. which one is available. the code written by the. NET Framework is hosted during execution (this stage is usually the runtime. that is, CLR manages applications by managing memory, processing security, and running for cross-language debugging.
advantages of hosted Code
platform independence: the same file containing byte code instructions can be placed on any platform, and the final stage of the compilation process during runtime can be dissolved. If you compile it into an intermediate language, you can obtain platform independence. Currently, you can only better support windows.
improved performance: msil is compiled in a timely manner. The JIT compiler does not compile the entire application once, but only the part of the code it calls. After the code is compiled once, the internal executable code is stored until the application is exited. Therefore, you do not need to re-compile the Code the next time you run the code. The last part of the compilation process is the exact JIT at runtime until the type of processor where the program runs, you can use any features provided by the processor or specific machine code to optimize final executable code.
language interoperability: It can compile any language into intermediate code, and the compiled code can interact with the Code Compiled from 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.