有元件的限制,可以被存储在列表? [英] Is there a limit of elements that could be stored in a List?

查看:91
本文介绍了有元件的限制,可以被存储在列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有元件的限制,可以被存储在列表?或者你可以保持添加的元素,直到你出的内存?

Is there a limit of elements that could be stored in a List ? or you can just keeping adding elements untill you are out of memory ?

推荐答案

表1所述的目前的执行情况; T> 使用的Int32 处处的 - 建设其底层实现数组,其计数属性,索引器,并为它的所有内部业务 - 所以有电流理论的最高 Int32.MaxValue 项目( 2 ^ 31-1 2147483647 )。

The current implementation of List<T> uses Int32 everywhere - to construct its backing array, for its Count property, as an indexer and for all its internal operations - so there's a current theoretical maximum of Int32.MaxValue items (2^31-1 or 2147483647).

但是,.NET框架也具有2GB的最大对象大小限制,所以你只得到附近的任何地方的项目限制与单字节项目,如名单,其中列出;字节&GT; 名单,其中,布尔&GT;

But the .NET framework also has a maximum object size limit of 2GB, so you'll only get anywhere near the items limit with lists of single-byte items such as List<byte> or List<bool>.

在实践中,你可能会耗尽连续内存的,你打任这些限制了。

In practice you'll probably run out of contiguous memory before you hit either of those limits.

这篇关于有元件的限制,可以被存储在列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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