Skip to main content
gamedev.net
🔒 Locked

[.net] [solved] c# maximal array size

Started by Nip Jun 22, 2007 at 6:53 PM 3 replies 1.1k views
Original Post
Nip
Nip
Hi I have a three-dimensional static array of floats, but as soon as I initialize it with e.g. [330,30,300] it crashes with an OutOfMemoryException. The real memory is not a problem, it has to be something else. Do arrays in c# have a maximum size? Does anybody have a solution for this? Nip [Edited by - Nip on June 24, 2007 12:24:53 PM]
Washu
Washu
There is no explicit memory limit except available memory and some upper bounds by the CLR GC. I'm not sure what is causing you to have that exception.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
Nip
Nip
Thanks for the reply, though it did not help much^^.

I continued looking for a solution and found the problem:

I used the array as below, which resulted in the exception:
float[,,] r = new float[300,30,300]

The following code works now, I just needed a jagged array:

int w = 300;
int h = 30;
int d = 300;

raster[][][] = new float[w][][];
for (int i = 0; i < w; i++)
{
raster = new float[h][];
for (int j = 0; j < h; j++)
{
raster[j] = new float[d];
for (int k = 0; k < d; k++)
{
raster[j][k] = testDVM.Testen(new Vector3(i, j, k) * cSize + bbox.pMinima, true)._Dist;
}
}
}
nagromo
nagromo
I'm guessing that the reason is because it didn't have 330*30*300*8=22.66MB contiguously free on the CLR's heap. Using a jagged array, it allocated several smaller arrays, which could fit in because they didn't have to be right next to eachother.
Nip
Nip
Thanks Nagromo, now I understand why it did not work. :)

I will mark the thread as closed now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.