为什么32位.NET进程的引用类型的最小大小为12个字节 [英] Why is the minimum size of a reference type 12 bytes for a 32 bit .NET process

查看:32
本文介绍了为什么32位.NET进程的引用类型的最小大小为12个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 Pro .Net性能关于参考类型内部的书籍部分.它提到对于32位.net进程,引用类型具有4个字节的对象标头和4个字节的方法表指针.另外,据说在32位系统上,对象对齐到最接近的4字节倍数,这使得引用类型的最小大小为12字节.

I was reading the Pro .Net Performance book section on reference type internals. It mentions that for a 32 bit .net process a reference type has 4 bytes of object header and 4 bytes of method table pointer. Also, says that on a 32 bit system, the objects are aligned to the nearest 4 byte multiple, which makes the minimum size of a reference type 12 bytes.

我的问题是,为什么最小大小为12个字节?对象是8个字节,并且已经与4个字节的边界对齐.

My question is, why is the minimum size 12 bytes? The object is 8 bytes and that already aligns with a 4 byte boundary.

推荐答案

垃圾收集实现的最低要求是12个字节.

Minimum of 12 bytes is a requirement of the garbage collection implementation.

从此处: http://msdn.microsoft.com/en-us/magazine/cc163791.aspx#S9

基本实例大小是由类加载器根据代码中的字段声明计算出的对象的大小.如前所述,当前的GC实现需要至少12个字节的对象实例.如果一个类没有定义任何实例字段,它将携带4个字节的开销.这8个字节的其余部分将由对象标头(可能包含同步编号)和TypeHandle占用.

The Base Instance Size is the size of the object as computed by the class loader, based on the field declarations in the code. As discussed previously, the current GC implementation needs an object instance of at least 12 bytes. If a class does not have any instance fields defined, it will carry an overhead of 4 bytes. The rest of the 8 bytes will be taken up by the Object Header (which may contain a syncblk number) and TypeHandle.

( TypeHandle 是方法表的句柄).

这篇关于为什么32位.NET进程的引用类型的最小大小为12个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆