New Features of CLR 4-Overview

Source: Internet
Author: User
Tags new set
ArticleDirectory
    • Introduction to CLR
    • Hosting and local code interoperability
    • Garbage Collection
    • Code conventions
    • Corrupted state exception
    • New Security Model
    • The same process, multiple CLR
    • Basic Class Library

. Net 4 released the latest version of the Common Language Runtime (CLR ). This version is another new version after CLR 2.0, including the hard work of the CLR team for several years.

Our team (CLR Shanghai team) plans to introduce some of these features in the next few months. This article serves as an overview. You are also welcome to reply to this article and tell us the topics you are interested in. We will further introduce them.

Introduction to CLR

As the most underlying component of the. NET Framework, CLR plays a role in running hosting.CodeThe role of a virtual machine, such as just in time compile and garbage collect. For example, if you think of the operating system as a binaryProgramThe CLR is the operating system hosting the World.

Figure 1 Location of CLR In the. NET Framework

As a part of the. NET Framework, CLR is always released with. net. However, in recent years, the release version of. net has been from 2.0 to 3.5, but the CLR has remained at 2.0, as shown in the following table:

. NetFramework Version

Time

CLR

1.0

2002.2

1.0

1.1

2003.4

1.1

2.0 (generics)

2006.1

2.0

3.0 (WPF/WCF/WF)

2006.11

2.0

3.5 (LINQ)

2007.11

2.0

4.0 Beta

2009.5

4.0

Figure 2 CLR version

As you can see, the release of 2.0 was three years ago. Over the past few years, the CLR team's work has finally been integrated into this release, let's talk about it one by one.

Hosting and local code interoperability

InterOP between hosted code and local code is responsible for external connections in the. NET world. For example, call a local DLL or COM component. In CLR 4, we have done the following to improve the usability of interoperability.

1. Custom Qi (custom Qi)

When the managed code is called by COM, it plays the role of the COM component. For COM components, iunknown: queryinerface (QI) is the key to type conversion. Before clr4, A Qi implementation was provided for each hosted COM component. clr4 allows users to customize QI. You can add interfaces, system. runtime. interopservices. icustomqueryinterface starts to understand this new feature.

2. tlbimpSource codeAnd custom tools

To call the COM component in the managed code, you need to declare your interface in the managed language, that is, InterOP assembly (IA ). Generally, you do not need to write these assemblies by yourself. Instead, you can use the tlbimp tool to generate Ia Based on TLB. During the development of CLR 4, we used the managed code to rewrite tlbimp and published the source code on codeplex.

One of the benefits of releasing tlbimp source code is to facilitate users to expand tlbimp functions by modifying the source code as needed. We also collected requirements from many customers for customizing tlbimp, extracted some of the most popular custom requests, produced tlbimp custom tools, and released them in codeplex. See http://blogs.msdn.com/silverlightshanghai/archive/2009/03/13/codeplex-tlbimp.aspx

3. Equivalent type

As mentioned above, to use COM components for. net, InterOP assembly is required. Different Versions of COM components bring about deployment problems. In CLR 4.0, we introduced the equivalent type to provide a better solution to the problem of deploying IA.

4. Miscellaneous

Other changes to InterOP, including customizing stub to handle callback alling and target function calls in InterOP; using COM to replace original remote object access; allowing users to decide their own time to clean up RCW, etc, A more detailed blog post will be provided.

Garbage Collection

Garbage collection has always been the core module in Clr and is crucial to the performance of hosted programs. In this version, CLR introduces background GC, which blocks other processes less during GC than the original concurrent GC, thus improving the overall CLR running efficiency. At the same time, the GC: registerforfullgcnotification introduced in SP2 allows clr4.0 to notify users of the second generation of GC, so that the server has the opportunity to handle load balancing, this prevents the processing capability of the entire server from being greatly affected by GC.

Code conventions

In clr4.0, code conventions are introduced to help users regulate code behavior. You can start with the namespace system. Diagnostics. Contracts to learn more about the content.

Corrupted state exception

In CLR 4.0, the philosophy of exception handling has been improved: by default, try/catch statements cannot catch exceptions such as accessviolationexception. Because these exceptions damage the state of the machine, even if the user captures them, it is very dangerous to continue executing the code.

New Security Model

Friends who have used the security model of CLR V2 may still remember concepts such as evision, policy, and permission. These complex objects have constructed the V2 security model framework together. In clr4.0, security models have been greatly simplified. security levels such as securitycritical and secursafecritical have built the foundation of new security models.

The same process, multiple CLR

The emergence of clr4.0 has added another CLR version. Although we try to ensure compatibility between different versions, some developed components may still appear, and a specific version is required for running. To ensure that the components written in the past cannot be run because of the new CLR version, clr4.0 allows users to run different CLR versions in a process, so that different components can be obtained separately, run in the CLR suitable for them.

Basic Class Library

The basic class library, that is, mscorlib. dll, includes the most core class libraries such as system. object in the entire type system. Clr4.0 also contains many new features, such as the system used to support dynamic languages. tuple, the new set type system. collections. generic. sortedset, an API used to improve the browsing performance of the file system, an API used to operate the registry, and support for memory ing files.

 

In general, compared with clr2.0, clr4.0 ensures high compatibility while doing a lot of improvement work. In subsequent blogs, the members of our team will give a more detailed introduction.

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.