CLR 是怎样去处理Boxing and Unboxing Value Types?
来源:互联网 发布:林天宝知乎 编辑:程序博客网 时间:2024/04/18 13:28
It's possible to convert a value type to a reference type by using a mechanism called boxing.
Internally, here's what happens when an instance of a value type is boxed:
1. Memory is allocated from the managed heap. The amount of memory allocated is the size
required by the value type's fields plus the two additional overhead members (the type
object pointer and the sync block index) required by all objects on the managed heap.
2. The value type's fields are copied to the newly allocated heap memory.
3. The address of the object is returned. This address is now a reference to an object; the
value type is now a reference type.
Unboxing is not the exact opposite of boxing. The unboxing operation is much less costly
than boxing.
Internally, here's exactly what happens when a boxed value type instance is unboxed:
1. If the variable containing the reference to the boxed value type instance is null,
a NullReferenceException is thrown.
2. If the reference doesn't refer to an object that is a boxed instance of the desired value
type, an InvalidCastException is thrown
- CLR 是怎样去处理Boxing and Unboxing Value Types?
- 6 important .NET concepts: - Stack, heap, Value types, reference types, boxing and Unboxing.
- 11.3 Boxing and unboxing
- Boxing and Unboxing
- Boxing and Unboxing
- Boxing and Unboxing
- BOXING AND UNBOXING FOR BEGINNER
- Boxing and unboxing in C#
- boxing, unboxing
- Java Auto Boxing and Unboxing -Java 学习笔记 (23)
- Effective C#之17:Minimize Boxing and Unboxing.
- 关于Boxing和Unboxing
- 关于boxing 和 unboxing
- CLR via C# 总结之Chap5 Primitive, Reference, and Value Types
- C#的Boxing/Unboxing解析
- java中的Boxing和unboxing
- java中的auto-boxing/unboxing
- C#中装箱和拆箱的作用 the effection of boxing and unboxing
- 第三场:浦和紅鑽 vs 曼聯
- DELPHI数据类型
- 另一个简单的binary_search算法:
- kfs嵌入式文件系统应用指南(一)
- Com 调用方式
- CLR 是怎样去处理Boxing and Unboxing Value Types?
- 咸水元子
- 几种排序算法
- 搜索引擎简史随笔记载(admin5.com)
- Oracle 9i Text对PDF的版本支持有问题
- JBPM 中的decision 使用
- 最新流行动画,风靡全球的《倒霉熊》,在线播放。搞笑。
- sqlplus 远程连接oracle语法
- 学好VC++的十大良好习惯