Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The limitation on the size of .Net array

Tags:

arrays

c#

I heard that there is a hard limit on the size of .Net Array. It is said that the maximum amount of memory that can be allocated to any single instance of an Array object ( regardless of whether it's int[], double[] or your own array) is 2GB. And no, if you have a 64 bit machine, the 2GB limit is still there.

I'm not sure whether my impression is correct or not. Anyone can confirm?

like image 660
Graviton Avatar asked Mar 10 '10 08:03

Graviton


People also ask

Is there a limit to array size?

The theoretical maximum Java array size is 2,147,483,647 elements.

What is the limit of array size in C#?

There is no fixed limit to the size of an array in C. The size of any single object, including of any array object, is limited by SIZE_MAX , the maximum value of type size_t , which is the result of the sizeof operator.

Can you increase the size of an array C#?

You cannot resize an array in C#, but using Array. Resize you can replace the array with a new array of different size.


1 Answers

In versions of .NET prior to 4.5, the maximum object size is 2GB. From 4.5 onwards you can allocate larger objects if gcAllowVeryLargeObjects is enabled. Note that the limit for string is not affected, but "arrays" should cover "lists" too, since lists are backed by arrays.

like image 68
Marc Gravell Avatar answered Sep 22 '22 14:09

Marc Gravell