开发者

Is there a limit of elements that could be stored in a List?

开发者 https://www.devze.com 2022-12-11 04:14 出处:网络
Is there a limit of elements that could be stored in a 开发者_StackOverflow社区List ? or you can just keeping adding elements untill you are out of memory ?The current implementation of List<T>

Is there a limit of elements that could be stored in a 开发者_StackOverflow社区List ? or you can just keeping adding elements untill you are out of memory ?


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).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号