I am attempting to allocate a very large multidimensional float array but an hitting out of memory exception issues when going above certain dimensions.
//Doesn't crash
float[,] newArr = new float[40000, 5000];
//Crashes
float[,] newArr1 = new float[45000, 5000];
//Doesn't crash
float[,] newArr2 = new float[40000000, 5];
//Crashes
float[,] newArr3 = new float[45000000, 5];
I am not sure what the issue is, I'm aware of array size limits of 2GB and 4 billion elements, but neither of these approaches either limit. Also, I cannot use another data struct because I need to pass the [,] to an external API call. Anyone have a clue what might be going on here? Thanks!
What I have experienced with your code is that it doesn't work when compiling (and running) in 32-bits mode. If I switch to 64-bits build mode, it does work.
So open your project settings > Compile and set Platform target to x64.
From Hans Passant:
45000 x 5000 x 4 ~= 900 megabytes. You are not going to get that in a 32-bit process, the largest hole in the available address space hovers around ~650 megabytes at startup and that goes rapidly downhill when your program has been running for a while. Just remove the jitter forcing so your program can run as a 64-bit process. Right-click your EXE project > Properties > Compile tab. Lots of really big holes in a 8 terabyte address space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With