CLR via C #--------the CLR execution mode

Source: Internet
Author: User

CLR: is a "runtime" that can be used by multiple programming languages.

The core capabilities of the CLR, such as memory management, assembly loading, security, exception handling, thread synchronization, can be used by all languages that target the CLR.

The CLR is fully expanded around the type.

CLR-oriented language compilers:

MICROSOFT:C++/CLI, C #, Visual Basic, F #, Iron Python, and IL assembler.

Other companies, colleges: Ada, PAL, Caml, COBOL, LOGO, PHP ...

Part of the Managed module: pe32/pe32+ header, CLR header, metadata, IL code.

Il is stack-based.

Il instruction when the "untyped" (typeless)

IL provides benefits: application robustness and security, abstraction of the underlying CPU.

When the IL compiles the cost to the CPU instruction, the CLR executes a process called validation. (Check the advanced IL code to make sure everything that the code does is safe.) )

In the elements of a managed module, contains all the method and type information to be used by the validation process.

In Windows, each process has its own virtual address space. (Ensure the robustness and stability of the program; one process cannot interfere with another process)

The advantage of managed code over unmanaged code is that running multiple applications in one operating system process can reduce the number of processes and thus enhance performance (Windows processes need to use a large number of operating system resources).

Unsafe code Usage scenario: code that directly operates memory addresses is called unsafe code and can manipulate the bytes at those addresses. This is usually done only when interoperating with unmanaged code, or when you are upgrading the performance of an algorithm that is highly efficient.

Unsafe code risk: potentially breaking data structures, compromising security, and possibly even creating new security vulnerabilities.

The C # compiler requires that all inventions containing unsafe code be legally marked with the unsafe keyword, requiring the use of the/unsafe compiler switch to compile the source.

Local code generator: NGen.exe

2. Use:

Speed up application startup.

Reduce the working set of the application.

Problems with files generated by 2.NGen:

No intellectual property protection.

Files produced by NGen may be out of sync.

Poor performance at execution time.

Because of these problems, it is important to be very cautious when considering shiyNGen.exe. for server-side applications, the role of NGen.exe is not obvious, or even useless , because only the first client request will experience performance degradation, and all subsequent client requests can run at full speed. In addition, for most server applications, you cannot derive any benefit from shrinking the working set because only one instance of the code is required. It is also important to note that images generated before ngen.exe2.0 cannot be shared between the AppDomain without mentioning a portion. Therefore, if an assembly is to be used in a cross-appdomain environment (such as ASP. NET), there is no benefit in generating it with NGen. (However, this restriction does not exist after NGen2.0.) )

For client applications, you might be able to use NGen.exe to speed up startup, or to reduce the toolset if the assembly is used by multiple applications at the same time. Even if an assembly is not used by multiple applications, generating it with NGen also helps to enhance the working set. In addition If a NGen.exe is used to generate all the assemblies for a client application, the CLR does not need to be added to the JIT compiler at all to further narrow the working set, although, of course, the JIT compiler is loaded as long as an assembly is not generated with NGen, or if a file generated by the NGen sound is not available to the Assembly, the application The working set of the sequence will increase.

Framework class Library

The Framework class library is included in the. NET framework. The FCL is a general term for a set of DLL assemblies that contains thousands of type definitions, each of which exposes some functionality.

The following lists some of the applications that application developers can create with these assemblies:

Web Service

Web Form

Windows applications

Ria

Windows Console Application

Windows Services

Database stored Procedures

Component Library

All applications use the type from the System namespace.

Part of the regular FCL namespace
Name space Content Description
System Contains all the basic types that are used by each application
System.Data Contains types for communicating with the database and processing data
System.IO Contains the language to perform flow I/O and browse directory/file types
System.Net Types that contain low-level network traffic and collaborate with some common Internet protocols
System.Runtime.InteropService Contains types that allow managed code to access unmanaged operating system platform features, such as COM components and functions in WIN32 or custom DLLs
System.Security Types that contain terms to protect data and resources
System.Text Contains types of text that handle various encoding methods, such as ASCII and Unicode
System.Threading Contains types for asynchronous operations and synchronization of resource access
System.Xml Contains types for working with XML Schemas (XML Schema) and data

Universal type System CTS

The CLR is fully expanded around the type. The CTS describes the definition and behavior of a type.

CTS Rules:

The 1.CTS specification specifies that a type can consist of 0 or more members. (Members include: Fields, methods, properties, events)

2.CTS Specifies the type visibility rules and the access rules for type members. (Private, protected, internal, public ...) )

3.CTS defines the corresponding rules for type inheritance, virtual methods, object lifetimes, and so on.

4. All types must eventually inherit from the System.Object type of the reservation one.

What the System.Object type allows:

1) Compare the equality of two instances.

2) Gets the hash code of the instance.

3) Query the True type of an instance.

4) perform a shallow (bitwise) Copy of the instance.

5) Gets a string representation of the current state of the instance object.

Common Language Specification CLS

COM allows you to create objects that communicate with each other in different languages. The CLR can integrate all languages, allowing objects created in another language to be used in one language. This integration is possible because the CLR uses standard type sets, metadata (self-describing type information), and the public execution environment.

CLS:CLS defines a minimum feature set in detail. Any compiler-generated type to be compatible with the components generated by other "CLS-compliant, CLR-oriented languages", the minimum feature set defined by the CLS must be supported.

Each language provides a subset of Clr/cts and a superset of the CLS (but not necessarily the same superset).

When you define a type in a language, you do not use any functionality outside the CLS in public and protected members of that type if you want to use that type in another language. Otherwise, when other developers write code in other languages, they may not be able to access this type of member.

Interoperability of managed and unmanaged code

The CLR supports three types of interop scenarios:

1. Managed code can call unmanaged code in the DLL

2. Managed code can use an existing COM component (server)

3. Managed types (servers) can be used by unmanaged code

CLR via C #--------the CLR execution mode

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.