开发者

Difference between CLR 2.0 and CLR 4.0

开发者 https://www.devze.com 2022-12-09 23:58 出处:网络
I have read countless blogs, posts and StackOverflow questions about the new features of C# 4.0. Even new WPF 4.0 features have started to come out in the open. What I could not find and will like to

I have read countless blogs, posts and StackOverflow questions about the new features of C# 4.0. Even new WPF 4.0 features have started to come out in the open. What I could not find and will like to know:

  1. What are the major changes to CLR 4.0 from a C#/WPF developer perspective?
  2. What are the major changes to CLR 4.0 as a whole?

I think, internally, most changes are for the new dynamic languages and parallel programming. But are there any other major improvements? Because language improvements are just that, language improvements. You just need the new compiler and those features can be used with a lower version of .Net, apart from version 1.0/1.1 (at least most of them can be used).

And if the above features are the only ones, only for these features the version is changed to 4.0, which I think is 4.0 because of being based on .Net 4.0 version (i.e. after 1.0/1.1, 2.0 & 3.0/3.5). Is the version i开发者_运维问答ncrement justified?

Edited:

As Pavel Minaev pointed out in the comments, even those two features are CLR independent. There were speed and other improvements in 3.0 and 3.5 also. So why the version increment?


One new CLR thing that I know about is a form of structural typing for interfaces, structs and delegates for the sake of NoPIA support - basically, it lets runtime treat distinct types with equivalent definitions as if they were the same - so if two assemblies A and B each have a COM-imported interface IFoo declared in them, with the same IID and same members, runtime will treat them as equivalent types; so if there's an instance some class Foo implementing [A]IFoo, you can cast it to [B]IFoo, and the cast will work.

One other thing is the ability to host several CLR versions side-by-side in a single process. You cannot host 1.x and 2.0 in one process, for example, but you can host 2.0 and 4.0. The main benefit for this is the ability to load plugins written for either CLR version concurrently.

One minor bit is that a few more exceptions have become uncatchable like StackOverflowException was in 2.0 - you cannot catch AccessViolationException anymore, for example.

Also, here is a PowerPoint presentation on CLR 4.0 from PDC 2008. It might be a bit dated now, but most stuff that's mentioned there seems to be in the betas.


There are a huge number of changes.

In the CLR itself, there are a few changes. The garbage collector is being changed to support concurrent collection of gen0/1 and gen2 in workstation mode. Also, there are some changes in how security is implemented. The parallel framework changes some of the CLR's implementation of the threadpool (which is not entirely managed, but part of the runtime itself). Also, there are some changes to the type system, mostly related to the new PIA COM support.

The biggest changes are probably more library/framework changes, rather than CLR changes. such as the integration of the DLR into the framework, and the new dynamic type. In terms of framework, you have the reactive framework, parallel library extensions, code contracts, tuple support, and lots of small changes (ie: Enum.TryParse, Lazy<T>, and tons of other small, but nice, improvements).


I don't believe there are any new IL instructions. The new CLR has improvements to things like inlining and garbage collection which do the same job as the 2.0 CLR, but better. A virtual machine (such as the CLR or JVM) is an abstract concept with multiple possible implementations. I believe CLR 4.0 is the same abstract machine as in CLR 2.0, just with an improved implementation.

Even the new dynamic stuff is just a compiler trick with new APIs (unlike in Java where it's being proposed as a new opcode.)

If I'm wrong about this, I'd love to know!


For each release documentation teams create "What's new" documents.

Here is the one for C# 4.0 Beta2: What's New in Visual C# 2010

And here is the one for .NET Framework 4.0 Beta2: What's New in the .NET Framework Version 4

These are the most complete lists of changes you can find.


Many core interface and delegate types in the CLR have been updated in support of generic covariance and contravariance. For example, IEnumerable<T> has been changed to IEnumerable<out T>.


Here are the Changes in CLR 4.0

  • New security model
  • Garbage collector improvements
  • Improved thread pool for TPL
  • Improved production diagnostics
  • Generic covariance and contravariance
  • Type system changes for PIA COM support
  • New GAC


I tried looking at some of the new C# stuff in Reflector, to see if there's anything new down under:

  • dynamic types are translated to objects, via compiler magic, which adds library calls to handle runtime binding.
  • Optional parameters are handled via the compiler. If you call Foo(int x = 5), without specifying a value for x, you'll see the call as Foo(5) in Reflector.

So I guess the changes are nothing you can easily spot (like generic support in CLR 2.0).

0

精彩评论

暂无评论...
验证码 换一张
取 消