什么是在一个List&LT最大的项目; T&GT ;? [英] What's the max items in a List<T>?

查看:101
本文介绍了什么是在一个List&LT最大的项目; T&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道哪些项目在列表中的最大数是?

Anybody know what the max number of items in a List is?

我如何增加大小?或者是有一个集合,需有极大的项目? (尽可能将适合在内存中,这是)

How do I increase that size? Or is there a collection that takes infinite items? (as much as would fit in memory, that is)

编辑:

我得到一个内存不足的异常时整数列表计数= 134217728。有3GB的内存,其中2.2是在使用中。声音正常。

I get an out of memory exception when Count = 134217728 in a list of ints. got 3Gb of RAM of which 2.2 are in use. Sound normal

推荐答案

列表< T> 将被限制到一个数组中的最大值,这是2GB的(即使是在64)。如果这还不够,你使用了错误类型的数据存储。您可以通过启动它的大小合适,虽然省了不少开销 - 通过传递 INT 来构造

List<T> will be limited to the max of an array, which is 2GB (even in x64). If that isn't enough, you're using the wrong type of data storage. You can save a lot of overhead by starting it the right size, though - by passing an int to the constructor.

重新您的编辑 - 与134217728点¯x的Int32,也就是512MB。请记住,列表&LT; T&GT; 使用加倍算法;如果你是通过滴喂项目添加(没有先分配所有的空间)它会尝试加倍到1GB(在你已经持有512MB的顶部,的您的应用程序的其余部分的,当然的CLR运行时和库)。我假设你在x86,所以你已经有一个2GB的限制的每个进程的,而且很可能你已经支离破碎你的大对象堆来的死亡的同时加入的项目。

Re your edit - with 134217728 x Int32, that is 512MB. Remember that List<T> uses a doubling algorithm; if you are drip-feeding items via Add (without allocating all the space first) it is going to try to double to 1GB (on top of the 512MB you're already holding, the rest of your app, and of course the CLR runtime and libraries). I'm assuming you're on x86, so you already have a 2GB limit per process, and it is likely that you have fragmented your "large object heap" to death while adding items.

就个人而言,是的,这听起来是正确的,开始在这一点上得到一个不折不扣的内存。

Personally, yes, it sounds about right to start getting an out-of-memory at this point.

编辑:在.NET 4.5,大于2GB的数组被允许,如果<一个href=\"http://msdn.microsoft.com/en-us/library/hh285054.aspx\"><$c$c><gcAllowVeryLargeObjects>开关被启用。然后限制为2 ^ 31项。这可能会为引用数组是有用的(每64 8个字节),或数组大结构秒。

in .NET 4.5, arrays larger than 2GB are allowed if the <gcAllowVeryLargeObjects> switch is enabled. The limit then is 2^31 items. This might be useful for arrays of references (8 bytes each in x64), or an array of large structs.

这篇关于什么是在一个List&LT最大的项目; T&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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