如何确定的对象的大小,C#? [英] How to determine size of an object, c#?
问题描述
我有以下类:
public class MyClass
{
public string Name { get; set; }
public int Age { get; set; }
public double Amount { get; set; }
}
当我试图找出这个类的大小在64位系统上通过使用WinDbg中,我得到了大小40
对此我无法理解,就我看过MyClass的应有
When I try to find out size of this class on a 64 bit system by using WinDbg I get the size 40 which I am not able to understand, as far as I have read MyClass should have
8 bytes for SyncBlock
8 bytes for TypeHandle
8 bytes for string reference
4 bytes for Int32
8 bytes for double
= 36 bytes
我没有10美誉,这就是为什么我不能够张贴的形象。
任何人有任何想法,为什么WinDbg的是显示4个额外的字节?
I don't have 10 reputation that's why i am not able to post image. Anyone has any idea why WinDbg is showing 4 extra bytes ?
推荐答案
我相信你所看到的是事情需要对齐到8字节边界的64位构建(4字节边界的32位版本)的效果。 40是最接近大小> = 36是一个8字节的边界上。这些链接谈对象大小:
I believe what you're seeing is the effect of things needing to align to 8 byte boundaries in 64 bit builds (and 4 byte boundaries in 32 bit builds). 40 is the closest size >= 36 that is on an 8 byte boundary. These links talk about object size:
钻成的.NET Framework内幕处见CLR如何创建运行时对象
这篇关于如何确定的对象的大小,C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!