Jump to content
  • Advertisement
Sign in to follow this  
Nip

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

This topic is 4168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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;
}
}
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Thanks Nagromo, now I understand why it did not work. :)

I will mark the thread as closed now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!