简体   繁体   English

C#中等大小集合中的大对象

[英]C# Large object in medium size collection

I'm pretty new to the memory problem. 我对记忆问题很新。 Hope you don't think this is a stupid question to ask. 希望你不要认为这是一个愚蠢的问题。

I know that memory larger than 85,000 Bytes would be put into LOH in C# ie 我知道大于85,000字节的内存将被放入C#中的LOH中

Byte[] hugeByteCollection = new Byte[85000]; 

I'm wondering if a collection with size 10000 - 20000 with an object that contains 10 member variables (byte type) will be put into LOH or SOH ? 我想知道一个大小为10000 - 20000且包含10个成员变量(字节类型)的对象是否会被放入LOH或SOH?

The size of an array of objects is the number of objects times the pointer size. 对象数组的大小是指针大小乘以的对象数。 This is because only value types is stored in the array itself, reference types (objects) will be stored somewhere else and will not count towards the size of the array. 这是因为只有值类型存储在数组本身中,引用类型(对象)将存储在其他地方,并且不会计入数组的大小。 So 85000/4=21250 objects, and 85000/8=10625 objects can be stored in an array on the SOH in 32bit and 64bit mode, respectively. 因此,85000/4 = 21250个对象,85000/8 = 10625个对象可以分别以32位和64位模式存储在SOH上的阵列中。

Edit: Thanks to Hans Passant for pointing out that this assumes that the collection type used is an array and not a list. 编辑:感谢Hans Passant指出这假定使用的集合类型是数组而不是列表。 Lists resize themselves to be bigger than the content to avoid too many allocations. 列表调整自身大小比内容大,以避免分配太多。 See this link for details 请参阅此链接了解详情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM