CLR 4.0 有哪些新东西? What's new in CLR 4.0--类型嵌入 Type embedding

简介: 前言 Foreword 自从2005年CLR 2.0发布之后, Microsoft有几年没有更新CLR了. 现在新的版本CLR 4.0即将发布. 本人看了几个英文博文. 综合起来, 摘录其要点. 用一个系列介绍几个CLR4.

前言 Foreword

自从2005年CLR 2.0发布之后, Microsoft有几年没有更新CLR了. 现在新的版本CLR 4.0即将发布. 本人看了几个英文博文. 综合起来, 摘录其要点. 用一个系列介绍几个CLR4.0的新特性. 为照顾英文不好的同学, 特用中英文对照的形式.

Microsoft has not upgraded CLR for years since it released CLR 2.0 in 2005. The new CLR 4.0 is about to release. I read English posts on internet. Do a summary and grab the important points in the English posts. I am going to make a series of posts about what’s new in CLR 4.0. The post is talking about “Type embedding”.

类型嵌入 Type embedding

过去我们用.net开发,部署Office应用时, 我们必须引入Office PIA(Primary interop assembly). 当部署之时, 我们必须在目标机器上安装Office PIA. 虽然Office PIA 体积不大(6M多), 但是这给我们多少带来一些不便.现在CLR4.0的类型嵌入特性给我们提供了一些方便.下面来比较一下: 过去我们开发Office应用, 需要加入Office PIA的引用, 编译后你的Bin目录会有你的程序集和Office PIA的程序集. 当你的应用程序运行之时,你会发现你的应用程序装入了Office PIA的程序集. 在CLR4.0中, 你可以通知CLR将你引用的那些Office PIA的类型嵌入到你的程序集中. 这样在部署之时, Office PIA的程序集就不必一同部署到目标机器上. 具体怎么做呢?

When we develop Office applications using .net in the past, we need to add references to the assemblies of Office PIA. When we deploy the applicaitons, we have to install Office PIA also on the target machines. The size of Office PIA is not so big(about 6M), but it still not convenient enough. Now CLR 4.0 represents us a feature called “Type embedding”. This will provides us conveniency. Let’s work through how we develop Office applications in previous versions of CLR. First step, we need to add reference to Office PIA assemblies, after compiling there are Office PIA assemblies in your bin folder along with your application’s assemblies. If you try to debug your application, you will find your application assembly loads Office PIA assemblies in memory also. In CLR 4.0, you can send a note to CLR that CLR only embeds the types your applicaiton referencing into your assembly. This way you do not need install Office PIA on target machines together with your applicaiton. How to do this?

首先在Visual Studio 2010中加入Office PIA的引用(这和过去一样), 然后在展开引用(References)节点, 找到Office PIA的引用, 在属性(Properties)窗口, 有一个”嵌入互操作类型”(Embed Interop Types), 将其设置成真(True), 再重新编译.

First step you need to add reference to Office PIA assemblies in Visual studio 2010(This is the same as what we did in the past), and then extend the “References” node of your project, click the Office PIA assembly, in “Properties” window, set “Embed interop Types” to True, and compile again.

CLR只将你引用到的类型放入你的程序集中, 同时在你引用到的类型之下, CLR只将你用到的方法和成员以原名称存入你的程序集. 那些未调用的方法将以一个_VtblGap调用来代替, 这些方法的名称将变成以_VtblGap开头的名字.

The CLR rips only the types necessary to complete the calls you have made from your application, and CLR extracts only the methods you have called and replaced all the other methods and Type members with the magic _VblGap calls. Those _VtblGap pseudo methods are emitted in place of unused methods to maintain vtable compatibility.

类型嵌入的限制 Limitations

不能嵌入IL (Can’t embed IL, meaning no classes or static method)

只有元数据能嵌入(接口, 代理, 枚举, 结构) Only metadata is locally embedded (interfaces, delegates, enums, structs )

只有从COM得到的类型才能嵌入. 并且编译器检查这些标签. Only types from Interop Assemblies can be embedded. Compilers check for these attributes

a. [assembly:Guid(…)]

b. [assembly:ImportedFromTypeLib(…)]

参考文献

Ahme的blog  “CLR 4.0: Type Embedding”   http://eknowledger.spaces.live.com/blog/cns!F475D4DE444DB1AB!3238.entry     此博文是英文的, 还配有图片, 英文好的同学可以读读.

mikelij 于 2009.3.8. 23:09

目录
相关文章
|
安全 架构师 编译器
鲲鹏开发重点-–扭转x86乾坤的挑战,ARM64内存模型
因为X86及其CISC架构生态的封闭性,中国市场对未来处理器的选择,将是更开放、更模块化的RISC架构。 鲲鹏处理器就是符合这个潮流的创新产品和生态,将直面一系列挑战,和Apple一样赢得这场挑战,来扭转X86的封闭性的乾坤,创造出中国的处理器新生态。
1548 0
鲲鹏开发重点-–扭转x86乾坤的挑战,ARM64内存模型
|
云计算 运维 存储
aPaaS平台是什么?aPaaS与PaaS有什么区别?
aPaaS和PaaS都可以完成软件的开发和部署,都支持云端访问,而两者的差异主要体现在用户人群和使用环境不一样。
aPaaS平台是什么?aPaaS与PaaS有什么区别?
|
存储 缓存 IDE
CAN通信的基本原理与实现方法
CAN通信的基本原理与实现方法
2450 1
|
NoSQL 算法 Linux
【内附完整redis配置文件】linux服务器命令设置redis最大限制内存大小,设置redis内存回收机制,redis有哪些回收机制
【内附完整redis配置文件】linux服务器命令设置redis最大限制内存大小,设置redis内存回收机制,redis有哪些回收机制
780 0
|
Java Linux Maven
Linux/Windows下安装Maven
Linux/Windows下安装Maven
208 0
|
存储 SQL API
VB中判断空的几种方法,Null, Missing, Empty, Nothing, vbNullString区别
VB中判断空的几种方法,Null, Missing, Empty, Nothing, vbNullString区别
|
编译器 C语言 C++
C/C++中int128的那点事
C/C++中int128的那点事
918 0
C/C++中int128的那点事
|
C++
新建.Net Core应用程序后引用项一直黄色感叹号怎么办?
我们在vs中创建.Net Core应用程序后,引用项可能出现黄色感叹号,正常情况下,这种黄色感叹号时能在项目创建成功之后迅速消失的,可也有些时候一直不消失,怎么办? 我们可以选中异常的项目,然后右键菜单,选择重新生成黄色感叹号即会消失。 重新生成之后:
2062 0
|
3天前
|
存储 人工智能 安全
AI 越智能,数据越危险?
阿里云提供AI全栈安全能力,为客户构建全链路数据保护体系,让企业敢用、能用、放心用