你可以使用List<列表<结构>>绕过2GB的对象限制? [英] Can you use List<List<struct>> to get around the 2gb object limit?

查看:300
本文介绍了你可以使用List<列表<结构>>绕过2GB的对象限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑起来反对在C#中的2GB对象的限制(这也适用于64位的一些讨厌的原因)与大集合结构的(估计规模4.2演出计)。

现在使用明显名单是要给我的大小4.2GB给予或采取一个名单,但将使用由更小的名单列表,其中又包含了结构的一部分,让我跳这个限制?

我在这里的理由是,这只是一个硬codeD限制在阻止我实例化一个9gig对象在我的64位平台的CLR,这是完全无关的系统资源。还列出了和数组是引用类型,所以含列出一个清单只会实际上包含引用到每个列表。因此,没有一个对象超过大小限制。

是否有任何理由,这是行不通的?我想尝试这个自己,但现在我没有手头上有内存分析器来验证。

解决方案
  

现在使用明显名单是要给我的大小4.2GB给予或采取一个名单,但将使用由更小的名单列表,其中又包含了结构的一部分,让我跳这个限制?

是 - 不过,如果你试图解决这个限制,我会考虑使用数组自己,而不是让名单,其中,T> 类管理阵列

在CLR 2GB的单个对象的限制正是如此,一个对象实例。当你做一个结构的数组(名单,其中,T> 内部使用),整个阵列是一个对象实例中的CLR。但是,通过使用名单,其中,名单< T>> 或锯齿状排列,每个内部列表/阵列是一个单独的对象,它可以让你有效的大小任意对象你希望。

在CLR队居然在博客这一点,并提供了一​​个样品 BigArray< T> 实现,它就像一个名单,其中,T> ,但确实在块管理内部为你。这是另一种选择越来越> 2GB的列表。

需要注意的是.NET 4.5将有选择提供大于2GB对象在x64 ,但它会是你必须明确地选择在具有。

I'm running up against the 2gb object limit in c# (this applies even in 64 bit for some annoying reason) with a large collection of structs (est. size of 4.2 gig in total).

Now obviously using List is going to give me a list of size 4.2gb give or take, but would using a list made up of smaller lists, which in turn contain a portion of the structs, allow me to jump this limit?

My reasoning here is that it's only a hard-coded limit in the CLR that stops me instantiating a 9gig object on my 64bit platform, and it's entirely unrelated to system resources. Also Lists and Arrays are reference types, and so a List containing lists would only actually contain the references to each list. No one object therefore exceeds the size limit.

Is there any reason why this wouldn't work? I'd try this myself right now but I don't have a memory profiler on hand to verify.

解决方案

Now obviously using List is going to give me a list of size 4.2gb give or take, but would using a list made up of smaller lists, which in turn contain a portion of the structs, allow me to jump this limit?

Yes - though, if you're trying to work around this limit, I'd consider using arrays yourself instead of letting the List<T> class manage the array.

The 2gb single object limit in the CLR is exactly that, a single object instance. When you make an array of a struct (which List<T> uses internally), the entire array is "one object instance" in the CLR. However, by using a List<List<T>> or a jagged array, each internal list/array is a separate object, which allows you to effectively have any size object you wish.

The CLR team actually blogged about this, and provided a sample BigArray<T> implementation that acts like a single List<T>, but does the "block" management internally for you. This is another option for getting >2gb lists.

Note that .NET 4.5 will have the option to provide larger than 2gb objects on x64, but it will be something you have to explicitly opt in to having.

这篇关于你可以使用List&LT;列表&LT;结构&GT;&GT;绕过2GB的对象限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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