王朝知道
分享
 
 
 

谁能帮我翻译一下,不要翻译软件翻译的

王朝知道·作者佚名  2012-09-14  
宽屏版  字体: |||超大  
 
分类: 教育/科学 >> 外语学习
 
问题描述:

The Two Types Offered by the CLR: Reference Types and Value Types

The CLR supports two kinds of object types: reference types and value types. Of the two, you will run into reference types much more often. Reference types are always allocated from the managed heap and the new operator returns the memory address of the object – the memory address refers to the object’s bits. There are some performance considerations to consider when working with reference types. First, the memory must be allocated from the managed heap, which could force a garbage collection to occur.

The CLR also supports “lightweight” types called value types. Value type objects are usually allocated on a thread’s stack (although they can be embedded in a reference type object) and the variable representing the object does not contain a pointer to an object; the variable contains the value of the object itself. Since the variable contains the object’s value, a pointer does not have to be dereferenced in order to manipulate the object. Value type objects do not come under the control of the garbage collector thus reducing pressure in the managed heap and reducing the number of collections required by an application over its lifetime.

The .NET Framework Reference documentation clearly indicates which types are reference types and which types are value types. When looking up a type in the documentation, any type called a "Class" is a reference type. For example, the Object Class, the Exception Class, the FileStream Class, and the Random Class are all reference types. On the other hand, the documentation refers to each value type as a "Structure". For example, the Int32 Structure, the Boolean Structure, the Decimal Structure, and the TimeSpan Structure are all value types.

When possible, you should use value types instead of reference types because your application’s performance will be better. In particular, you should declare a type as a value type if all of the following are true:

• The type acts like a primitive type

• The type doesn’t need to inherit from any other type

• The type will not have any other types derived from it

• Objects of the type are not frequently passed as method arguments since this would cause frequent memory copy operations hurting performance.

Understanding Boxing and Unboxing

Value types are lighter-weight than reference types because they are not allocated in the managed heap, not garbage collected, and not referred to by pointers. However, there are many cases where you must get a pointer to a value type object. For example, if you want to add the integer 5 to an ArrayList, then your code would look like this:

参考答案:

由统计复用两种: 参考价值类型的种类和支持统计复用两种对象类型:类型和参考价值类型. 上述两个,你会更常碰到的参考类型. 参考类型总是分配由新经营效益和管理堆内存地址对象 -内存地址所指的对象的比特. 有些工作绩效考量,考虑当参考类型. 首先,必须分配内存从管理堆,这可能迫使垃圾发生. 还支持统计复用的"轻量级"类商品种类称为. 通常价值型物体分配一个线程的栈(虽然他们可以参考嵌入型物体) 代表和可变对象不包含指针的对象; 可变物体本身含有价值. 自变量包含对象的价值 指不须dereferenced为了操纵物体. 价值型物体不受到控制的压力大大减轻了拾荒者的管理堆 而收藏所需人数降低其寿命超过申请. <. NET框架参考文献清楚地表明这是种类型,其中类型是参考价值类型. 当仰视型的文件,任何类型称为"级"是指类型. 例如,对象类,除了在课堂上filestream阶级、阶层都是随机参考类型. 在另一方面,该文件是指每一个价值型"结构". 例如,int32结构、布尔结构、小数结构、商品种类都timespan结构. 如果可能的话,你应该使用类型而不参考价值,因为你的应用类型的表现会更好. 特别要申报作为一种价值型若以下全部属实: ●行为型原始型●喜欢的类型不需要继承自任何其他类型—次 电子类不会有任何其他类型的对象从它的种类●不经常通过 因为这会引起争议的方法频繁内存拷贝操作伤害表现. 拳击、unboxing认识价值类型的打火机体重比参考类型,因为他们不是在设法拨出堆、 不是垃圾,不要提及的指点. 不过,有许多情况下,你一定要以价值型指针对象. 举例来说,如果你想要添加一个整数5arraylist,那么你的代码将像这样:

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
如何用java替换看不见的字符比如零宽空格&#8203;十六进制U+200B
 干货   2023-09-10
网页字号不能单数吗,网页字体大小为什么一般都是偶数
 干货   2023-09-06
java.lang.ArrayIndexOutOfBoundsException: 4096
 干货   2023-09-06
Noto Sans CJK SC字体下载地址
 干货   2023-08-30
window.navigator和navigator的区别是什么?
 干货   2023-08-23
js获取referer、useragent、浏览器语言
 干货   2023-08-23
oscache遇到404时会不会缓存?
 干货   2023-08-23
linux下用rm -rf *删除大量文件太慢怎么解决?
 干货   2023-08-08
刀郎新歌破世界纪录!
 娱乐   2023-08-01
js实现放大缩小页面
 干货   2023-07-31
生成式人工智能服务管理暂行办法
 百态   2023-07-31
英语学习:过去完成时The Past Perfect Tense举例说明
 干货   2023-07-31
Mysql常用sql命令语句整理
 干货   2023-07-30
科学家复活了46000年前的虫子
 探索   2023-07-29
英语学习:过去进行时The Past Continuous Tense举例说明
 干货   2023-07-28
meta name="applicable-device"告知页面适合哪种终端设备:PC端、移动端还是自适应
 干货   2023-07-28
只用css如何实现打字机特效?
 百态   2023-07-15
css怎么实现上下滚动
 干货   2023-06-28
canvas怎么画一个三角形?
 干货   2023-06-28
canvas怎么画一个椭圆形?
 干货   2023-06-28
canvas怎么画一个圆形?
 干货   2023-06-28
canvas怎么画一个正方形?
 干货   2023-06-28
中国河南省郑州市金水区蜘蛛爬虫ip大全
 干货   2023-06-22
javascript简易动态时间代码
 干货   2023-06-20
感谢员工的付出和激励的话怎么说?
 干货   2023-06-18
 
>>返回首页<<
 
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有