Reputation: 16512
I'm trying to initialize a jagged array of 120 000 x 4600 for a data mining algorithm but I have an OutOfMemoryException
exception
double[][] array = new double[120000][];
for (int i = 0; i < array.Length; i++)
{
array[i] = new double[4600];
}
it throws when i
is around 49 000
I know .Net is limited to 2GB per object, but I thought that the array here would be a list of addresses to an array of double. So it wouldn't be a big single object.
I thought that's why Jon Skeet suggests an jagged array for this question OutOfMemoryException on declaration of Large Array
I don't think that I understand his answer.
Is it one big object and if it's not why does it throw an exception.
Thank you
Upvotes: 1
Views: 245
Reputation: 30728
If it is 32-bit application, You are rightly getting OutOfMemoryException
. For this size requirements you need to target X64.
At i = 49000, Total memory = 49000*4600*8 = 1803200000 bytes = ~1.68GB.
Now For 32-bit applications (targeted X86), Total User Memory avaiable to an application is 2GB (unless the application is Large address aware, .NET application - Large Address Aware and OS is also enabled for this. Ex: (for)Vista. Then there is some CLR overhead, then application overhead.
At i = 120000, You need total memory as Total memory = 120000*4600*8 = 1803200000 bytes = ~4.11GB. (Platform target should be X64)
Upvotes: 2