Original: http: //www.c-sharpcorner.com/Code/2004/May/WhitePapers_DotNetFramework.asp Author: Chandrakant P Parmar translation: Ping Road, also address: http: //blog.9cbs.net/luyiping/archive/2004 / 06/22/22556.aspx
Quick understand .NET Framework
introduction
This article focuses on Microsoft .NET framework. This is a newly released software development environment that helps developers quickly develop applications and provide a variety of different languages like Visual Basic .NET, C #, ASP .NET, and JScript .NET, etc., the most appropriate, efficient, available Extended, performance-oriented applications.
.NET Framework Overview .NET Framework is a new computing platform that simplifies application development in Internet height-distributed environments.
service
The NET framework provides the following services:
Development Software Application Tools Execute software applications Runtime Environment Server Infrastructure helps developers reduce value-added value-added to improve work efficiency
The .NET framework will enable developers to develop applications for different devices and different platforms, such as Windows applications, web applications, Windows services, and Web services.
the goal
Design .NET framework is to achieve the following goals:
A consistent object-oriented programming environment, the target code is localized to store and execute, localized execution rather than distributed Internet, or remote execution. A reduced code editing environment for software deployment and version conflicts. A code editing environment that ensures a secure code, including the code from unknown or unable to trust. A code editing environment that can eliminate the performance problem caused by a script or interpretative environment. Developers have a consistent development experience in the face of a large number of different application system, such as Windows-based applications and web-based applications. Construct all industrial standard information to ensure that the .NET framework-based code can integrate any other code.
Understand the .NET frame architecture
The .NET framework has two components: .NET Framework class library and public language run. The .NET Framework class library makes the type (CTS) makes simple, it is public for .NET language. The integration of the public language runtime is: (class loader) Loading the IL code of the program and the compilation cost code to the runtime, executes and manages the code to enhance security and type security, and provide thread support.
The top of the .NET frame architecture is the language like VB .NET C #, VJ #, VC .NET; developers can develop (using any language above) like Windows Forms, Web Forms, Windows services, and XML Web service.
Understand the role of the .NET framework
The .NET framework has two sets of components: Public Language Runtime (CLR) and .NET Framework Category Library. The public language is based on the basis of the .NET framework. CLR management code, providing core services like memory management, thread management, and remoting, while strengthening strict types of security and promoting code correctly ensures the security and robustness of the program (robustness). The concept of code management is the basic principle of CLR. The code for the CLR is considered to be manageable code, rather than the code for the CLR, is considered unrecognizable code.
The class library is a full component of the .NET framework, including object-oriented collection of available classes, which enables us to develop applications to include traditional command lines or anything like Windows Forms, ASP. Net Web Forms and New modern XML Web Services Windows Services This graphical user interface (GUI).
The European Computer Manufacturer Association (ECMA) standard defines a general language specification (CLS); this enhances software development language to interoperate. The code written according to CLS should be able to compile with another CLS language code. Since the code that is supported by the CLS language will be compiled into an intermediate language (IL) code. The CLR engine executes IL code. This ensures the interoperability of the CLS language. Microsoft .NET framework supported language with Microsoft Visual Basic .NET, Microsoft Visual C #, Microsoft Visual C .NET, and Microsoft Visual J # .NET. Language Compiler Generates Intermediate Language Code, called Microsoft Intermediate Language (MSIL), which makes it different Interoperable .NET language written programs. ECMA Standard, Public Language Architecture (CLI) defines the specification of the infrastructure that IL code needs to be executed. The CLI provides a public type system (CTS) and a type of security, manageable code execution, and SIDE BY SIDE execution.
Figure 1. Microsoft .NET frame ECMA standard
The .NET framework provides infrastructure and services. CLI specification. They include: public language runtime:
CLR includes CLI
The CLR also provides an enforcement environment for .NET applications
Public type system:
Provide data type, value, object type. This makes developers to develop applications in different languages. .NET language shared CTS means that all types in the application are in the CLI type definition.
Type security:
The .NET framework performs actions on values and objects, because .NET Framework needs to know the type of each value and object and reference values, and object types.
Manageable code execution
The .NET framework manages the status of the object when the .NET application is time.
The .NET framework automatically assigns memory and provides aircraft collection mechanism to reassign memory
Side-by-side execution
The .NET framework allows the same machine to run on the same machine by using different versions of the assembler to operate on the same machine. The assembler consists of IL code and metadata. Metadata determines the dependency of the application. With this, the .NET framework can perform a variety of version of the assembly and resolve the main problems of the legacy development environment. That is DLL HELL?
.NET assembler Figure 2 Side-by-side execution
Understand .NET Framework CLR
Public language runtime:
Runtime environment
CLR compiles the application into running, compiles the IL code into the local code, executes code
Runtime service
Memory management
Type security
Enhanced security
Abnormal management
Thread support
Debugging support
Understand the architecture of the .NET framework CLR
The class loader loads the class to the CLR.
MSIL to the compilation of local code will convert MSIL to local code.
Code Manager, it is managed during code execution.
Memory allocation and garbage collection, performance is automatic memory management.
Safe engine, using Microsoft's tools and to enhance security restrictions on the control panel to the .NET framework, including code level security, file, and machine level security.
Type Checker, enhance strong type check.
Thread support provides multi-threaded support for the application.
Abnormal Manager provides a mechanism for operating anomalous processing at runtime.
The debug engine allows developers to debug different types of applications.
COM configuration, allows .NET applications to exchange data with COM applications.
The base class library support provides the class required to run the application. Characteristics of public language runtime
CLR has the following characteristics:
Manage memory:
Memory allocation
Reliassment of memory (garbage collection)
Thread execution support
Code execution
Code security check
Compile
MSIL to local code
Based on trusted code security (authorization to execute code. Code level, file level, machine-level) These features are inherent to run manageable code running in public language runtime. Understanding CLR For executive procedures and obtains management execution environments, we write code with CLS supported .NET Framework language. The language compiler compiles the source code into MSIL code composed of CPU-related code and platform-related instructions. MSIL has the following composition:
Can perform an instruction for arithmetic and logical operations.
Access memory directly.
Control execution stream
The processing exception MSIL code can be compiled into a particular CPU instruction before execution, and the information required by the CLR is only metadata. Metadata Description Code and define the code type includes other types of reference code used in the running period.
An assembler consists of a streamlined executable. Be executed
PE
When the file is time-loaded
MSIL
The code is metadata to encrypt the streamlined executable.
The PE file is executed to transfer the code to the local code compiler to compile, and the compilation of IL to the local code is completed. Because different CPU architecture and compiler IL code to local instructions.
CLR characteristics
Managed multi-threaded support and thread monitoring. The application field includes one or more execution threads.
Manage the interoperability of unsafe code, and COM configuration.
Structured abnormal processing mechanism
The structure of the infrastructure and management execution process, memory management and garbage collection CLR
Base class library supports all base classes that use .NET language to support basic functionality.
The COM configures recombination supports data between COM objects.
Abnormal Management Support Using the TRY Catch Finally statement block handling errors during runtime.
The security engine enhances safety rules at runtime.
Type Checkered Type Safety Check at runtime.
The debug engine supports runtime debugging.
Code Manager Manage Code when managing runtime
IL to the local code compiler to compile MSIL code into machine-related local code
The garbage collector supports memory management and supports memory-discarded memory. The class loader is loaded at runtime.
Understanding the JIT compiler JIT compiler as a complete portion of the CLR to compile the MSIL code into the local code and perform the entire batch code in real time. The code will be cached and next to read code from the cache again compile (translation) JIT execution process CLR class loader loads MSIL code and load metadata to memory; Code Manager calls WinMain or DLLMAIN method . The JIT compiler compiles this method before its entry method is executed. The code manager places the object in memory and controls the execution of the code. The garbage collector implements an invalid object for the periodic inspection of the management stack. The program execution Type Checker Make sure all objects and values and references to objects and values have their legal types. Type Checker also guarantees the unique legal operation of the code, otherwise it will throw an exception. The code is controlled by CLR at runtime. CLR enhances security in the following behavior:
Control and access system resources like hard drives
Control and access network connection
Control and access other hardware resources
Managed code to execute the management code to perform the process being performed by the CLR, with the following aspects:
CLR loads MSIL and application metadata
CLR performs local code,
CLR provides automatic memory management
Managed implementation also implements JIT editing
Package type safety,
Enhanced security
Abnormal processing
Managed execution process
Managed code is self-explanatory code, which gives the information on the CLR running service in the .NET framework.
This information is stored in the MSIL code in the form of metadata in the PE file. Metadata information will describe the type of code contain.
Managed data is automatically assigned and released by the garbage collector. Managed code can be managed to be managed instead of management data can be managed. (Incorrect turning)
Memory management
Automatic memory management means that memory does not need to write code to allocate memory or when the application does not require objects.
Automatic memory management process includes the following tasks:
? Allocate memory
When a process is initialized, a consecutive address space is retained without allocating any storage space.
This reserved address space is called a hosted stack. The hosted pile retains a pointer in the place where the next object is placed.
When an application creates an object with the New operator, the New operator checks if the memory required by the inside of the stack is available. When the next object is created, the garbage collector assigns memory to the object in the hosted stack.
There is less time to the object to the object to be used in the hosted heap allocation than the distribution of the non-managed stack.
In the non-hosting heap, the pointer to the memory is maintained in the chain table data structure. Therefore, allocation of memory needs to be used by manipulating the chain, looking for a larger memory block capable of accommodating it. (The original text is not full)
Objects you can access to managed memory more quickly than accessing non-managed memory, because the object is always assigned in the managed address space when hosted memory allocation. ? Release memory
The garbage collector periodically releases memory in the object that is no longer needed.
Each application has a set of root pointers. The root pointer points to the storage position in the hosted stack. Each root pointer or an object in the hosted stack or is spaced.
The root pointer of an application consists of global static pointer, local variable, and reference object parameters on the thread stack.
The JIT compiler and the runtime maintenance of the list of application root pointers. The garbage collector uses this list to create object charts in the hosted stack in the hosted stacks using this list.
When the garbage collector starts, it looks all the objects in the hosted stack as garbage.
The garbage collector is operated by the root pointer list of applications, which defines the objects that have the appropriate references in the application root pointer list and mark the available objects.
The garbage collector also uses such an object as an object. (do not know the meaning)
The garbage collector believes that the objects that are not available in all hosted stacks are garbage.
Garbage collector uses the collection process to release the garbage object space.
The garbage collector uses the memory replication function to compress the objects in the hosted stack.
The garbage collector updates the pointer in the application root pointer list so that the earlier application root pointer corrects the object.
Garbage collectors use highly optimized mechanisms to complete waste collection. It divides the objects in the hosted pile into three: 0, 1, and 2. Level 0 includes the most recently created objects.
The garbage collector begins to collect unaptible objects at level 0. Then, the garbage collector is tightening memory and enhances the subject to level 1.
Flexible to the collection of objects collected by the process is improved to a higher level.
The garbage collector searches for unaptible objects at level 1 and level 2, which is only when the memory release of the column 0 object is not enough to create a new object.
The garbage collector manages memory for managed objects created by all applications.
The garbage collector can explicitly release these system resources by providing clearing code in the DISPOSE method such as object.
We need to display the Dispose method after the object is completed.
? Realize completion
The completion process allows an object to complete the cleanup work before the garbage collector starts.
The Finalize method ensures that even if the customer does not explicitly call the Dispose method, the resources used will also be released from memory when the object is garbage.
After garbage collection, the identification object is used, it is a Finalize method that calls an object in advance in the release within the release.
The completion device is a method of cleaning code that is executed before the object is collected. The process of performing the cleaning code is called the end. Dispose and Finalize methods are called completions.
The DISPOSE method of the object releases all resources, including its parent object owned by the resource by calling the Parent object.
We have two ways to perform Dispose methods:
Class users can transfer the Dispose method of the object, or
The Finalize method can call the Dispose method during the end of the end.
Understanding ...