.NET集合和大对象堆(LOH) [英] .NET Collections and the Large Object Heap (LOH)

查看:152
本文介绍了.NET集合和大对象堆(LOH)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有大量项目的.NET集合是否容易存储在LOH中?

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

我对特定的列表和字典很好奇。在我的代码中,我存储了大量(40k +)的相对较小的对象(让我们说1k)在临时列表和字典中进行处理。这些集合中的项目数是否增加了被放在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被实现为双向链表,的元素不应该增加实际的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.

感谢

推荐答案

对象将只存储在LOH,如果他们超过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.

但是,Dictionary不太可能,因为它们存储了一个桶的数组,所以除非生成足够的桶,所以数组变成> 85000字节,这是不太可能的。即使它们是类(因为每个元素中的对象引用将导致列表在x86上为160k,在x64系统上为320k),所以将在LOH上存储40k个元素的列表。

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.

如果你使用一个双向链表而不是一个标准的List,它是很不可能它会被存储在LOH上。列表中的每个元素都将很小(只有一个节点引用了下一个/上一个节点),因此没有一个对象大于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.

在LOH上,这是一个很棒的博客条目。

这篇关于.NET集合和大对象堆(LOH)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆