如何确定对象的大小,c#?
发布时间:2020-12-15 17:43:28 所属栏目:百科 来源:网络整理
导读:我有以下类: public class MyClass { public string Name { get; set; } public int Age { get; set; } public double Amount { get; set; } } 当我尝试通过使用WinDbg在64位系统上找出这个类的大小时,我得到的大小为40 我无法理解,只要我看到MyClass应该有
我有以下类:
public class MyClass { public string Name { get; set; } public int Age { get; set; } public double Amount { get; set; } } 当我尝试通过使用WinDbg在64位系统上找出这个类的大小时,我得到的大小为40 8 bytes for SyncBlock 8 bytes for TypeHandle 8 bytes for string reference 4 bytes for Int32 8 bytes for double = 36 bytes 我没有10个声望,所以我无法发布图像. 解决方法
我相信你所看到的是需要匹配64位构建中的8字节边界(和32位构建中的4字节边界)的效果. 40是在8字节边界上的最接近的大小> = 36.这些链接谈论对象大小:
Of Memory and strings (Jon Skeet’s blog) Benchmarking C# Struct and Object Sizes Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects How Much Memory Does a C# String Take Up (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |