Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 667
Hannoun Yassir Avatar asked Nov 13 '09 17:11

Hannoun Yassir


People also ask

How many elements can you store in a list?

1) Yes, list can store 100000+ elements. The maximum capacity of an List is limited only by the amount of memory the JVM has available. 2) For performance issues, it depends on the type of data to be stored. Normaly HashMaps are used for databases.

How many elements can an array store?

We can store elements only up to a [10000000] (10^7) in a array of integers.Is there a way to store even more number of data's.

What is limit of list in C#?

2147483647 because all functions off List are using int.


1 Answers

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.

like image 62
LukeH Avatar answered Sep 27 '22 15:09

LukeH