What maximum number of items can I put inside a ListT in C #?

7

I have several performance doubts in my application. What is the maximum number of items that I can get within my List<T> and what is "acceptable" within good practices.

    
asked by anonymous 01.08.2017 / 17:04

1 answer

8

Since the object access index type of List is a int the theoretical limit is 2 raised to 31 or 2,147,483,648.

But this is more complicated than it sounds. In general each object can have only 2GB of total size allocated. So the amount of items you can actually have depends on the type T . The larger it is, the fewer items it can allocate. Remembering that% s of% is a type by reference its size is always 4 or 8 bytes depending on the architecture.

There is one more detail. On 64-bit it is possible to connect the ability to increase the size of the object with the framework directive T (available in 4.5 forward), in thesis it is possible to work with all the items that the index supports. Just think it will be handy with small objects or reference, and preferably if you have lots of RAM.

If you need more than 2 billion in need of a different structure, you can even use <gcAllowVeryLargeObjects> as a reference and change the index to a List that is virtually impossible to burst.

Remember that anything that makes virtual memory act to be exchanging pages from RAM to secondary storage like HDD or SSD can make the application a tragedy of performance. And since this good practice business is soft talk, you have no way of knowing when you overcame it. You have to measure, have to analyze, simulate, have to specify where your application can run well and let the person accept the degradation if they run with less RAM than you specified.

    
01.08.2017 / 17:15