我有以下类:
public class MyClass { public string Name { get; set; } public int Age { get; set; } public double Amount { get; set; } }
当我尝试通过使用WinDbg在64位系统上找出这个类的大小时,我得到的大小为40
我无法理解,只要我看到MyClass应该有@H_404_6@
8 bytes for SyncBlock 8 bytes for TypeHandle 8 bytes for string reference 4 bytes for Int32 8 bytes for double = 36 bytes
解决方法
我相信你所看到的是需要匹配64位构建中的8字节边界(和32位构建中的4字节边界)的效果. 40是在8字节边界上的最接近的大小> = 36.这些链接谈论对象大小:
Of Memory and strings (Jon Skeet’s blog)@H_404_6@
Benchmarking C# Struct and Object Sizes@H_404_6@
Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects@H_404_6@