1

Why can't I use arrays bigger than 2 GB? Is there a deeper problem or is it simply implemented on int?

It seems that .net core throws an exception if I try to allocate a array with 10 billion elements:

int[] bigArray = new int[10_000_000_000]; // throws exception
user2033412
  • 1,950
  • 2
  • 27
  • 47
  • I don't know... But that will be an ugly array. – Jaider Sep 23 '17 at 12:43
  • Implementation of array from [Reference source](http://referencesource.microsoft.com/#mscorlib/system/array.cs) – Bakudan Sep 23 '17 at 12:45
  • Your question title is wrong. You can create arrays larger than 2gb. How did you calculate you are allocating 2 gb? From my calculation your array should be approximately 3 gb. – Patrick Hofman Sep 23 '17 at 14:55
  • 1
    Because Lenght property returns Int32, and it's maximum value is about 2 billions. However there is LongLength property – yanpas Jul 19 '18 at 13:34

0 Answers0