.NET集合和大对象堆(LOH)对象、NET、LOH

2023-09-02 02:01:48 作者:凹凸先森

是.NET集合与大量物品易于被存储在所述的LOH?

Are .NET collections with large number of items apt to be stored in the LOH?

我很好奇列表和字典明确。在我的code,我店比较小的物体大量(40K +)(可以说1K)的临时列表和Dictionarys进行处理。有没有项目在这些集合的数量增加被提上LOH的可能性有多大?

I'm curious about List and Dictionary specifically. In my code, I store a large number (40k+) of relatively small objects (lets say 1k) in temporary Lists and Dictionarys for processing. Does the number of items in these collections increase the likelihood of being put on the LOH?

有关名单,假设名单是作为一个双向链表,那么元素的数目应该不会增加实际List对象的大小,但我想知道。

For list, assuming that List is implemented as a doubly linked list, then the number of elements should not increase the size of the actual List object, but I'd like to know for sure.

感谢

推荐答案

对象将只存储在蕙,如果他们超过85,000字节。大名单(尤其是结构)会经常到这里来分配。

Objects will only be stored on the LOH if they are over 85,000 bytes. A large list (especially of structs) will often get allocated here.

然而,字典的可能性较小,因为他们是存储桶的阵列,因此,除非在产生足够的桶以使阵列变得> 85000个字节,这是不太可能的。 40K的元素列表将被存储在蕙,即使他们班(因为每个元素的对象引用将导致列表为160K在x86,320K在x64系统)。各个要素将在标准堆,不过,这样会得到夯实,等等。

However, Dictionary's are less likely, since they're storing an array of buckets, so unless the generate enough buckets so the array becomes >85000 bytes, it's unlikely. A list of 40k elements will be stored on the LOH, even if they're classes (since the object references in each element will cause the list to be 160k on x86, 320k on x64 systems). The individual elements will be on the standard heap, though, so will get compacted, etc.

如果您使用的是双向链表,而不是一个标准的名单,这是不太可能,它会被存储在LOH。列表中的每个元素将是小的(只是一个单一的与引用到下一个/ previous节点节点),所以没有单一的对象将是> 85K字节。

If you are using a doubly linked list instead of a standard List, it is very unlikely that it will get stored on the LOH. Each element of the list will be small (just a single node with references to the next/previous nodes), so no single object will be >85k bytes.

有关蕙的细节,这是一个伟大的博客条目。