jeudi 22 avril 2021

Why is Max size of int array lower than Int32.MaxValue? [duplicate]

For some reason if you create an int array of size Int32.MaxValue, it throws an OutOfMemoryException: Array dimensions exceeded supported range.

It seems like the maximum size that an array can be initialized to is Int32.MaxValue - 1048576. 1048576 is 2^20. So only this works:

var maxSizeOfIntArray = Int32.MaxValue - 1048576;
var array = new int[maxSizeOfIntArray];

Does any one know why? Is there a way to create a larger integer array?

PS: I need to use arrays instead of lists because of a Math.Net library that only returns arrays for sets of random numbers that are cryptographically secure pseudo random number generator

Yes I have looked at the other questions linked but they are not correct as those questions say the largest size is Int32.MaxValue which is not the same as what my computer lets me do

Yes, I do know the size of the array will be 8GB, I need to generate a data set of billions of rows in order to test the randomness with the die harder suite of tests




Aucun commentaire:

Enregistrer un commentaire