得到的名单,其中字节数; T>字节、名单、GT

2023-09-04 10:36:06 作者:逗霸( ‵o′)

愚蠢的问题,但在WinForms应用程序即时通讯目前正在研究,我想获得分配的字节/使用量的名单,LT; SomeObject]> 保存在内存中(用于统计目的)。这可能吗?我已搜查直通可能的选项,但显然没有 myList.GetTotalBytes()方法。

Silly question, but in a winforms app Im currently working on, I would like to get the amount of bytes allocated/used by a List<[SomeObject]> held in memory (for statistical purposes). Is this possible? I have searched thru the possible options, but there is obviously no myList.GetTotalBytes() method.

推荐答案

我不知道在运行时提供获取对象的大小的可靠的编程方法,但也有一些选项开放给你:

I'm not sure the runtime provides a reliable programmatic method of getting an object's size, however there are some options open to you:

使用像CLR分析器系统工具 使用Marshal.SizeOf() (返回对象的非托管大小) 在一个近似序列化对象的二进制 use a tool like CLR Profiler use Marshal.SizeOf() (returns the unmanaged size of the object) serialize your object to binary for an approximation