Jump to content
  • Advertisement
Sign in to follow this  
TutenStain

Max array size C++?

This topic is 3007 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

I need a way to store a lots of numbers for a .3ds model loader. The problem is that it crashes when I try to increase the array. Like: Works: float X[2][5000]; float Y[2][5000]; float Z[2][5000]; Instant crash: float X[10][5000]; float Y[10][5000]; float Z[10][5000]; Have I reached some kind of a limit on the array size or what?

Share this post


Link to post
Share on other sites
Advertisement
Probably; you might have reached the stack size limit. You can increase the stack size in Visual C++, under Project Properties, Linker, System.

Share this post


Link to post
Share on other sites
Or allocate dynamically, assuming you have a 32-bit system, each array takes 5000 * 10 * 4 = 200.000 bytes. There's enough of that on the heap:

float *X = new float[10 * 5000];
X[(y * 5000) + x] = 5.0f;
delete[] X;

Share this post


Link to post
Share on other sites
Quote:
Original post by _fastcall
Probably; you might have reached the stack size limit. You can increase the stack size in Visual C++, under Project Properties, Linker, System.


What do I need to change? This is what I see: http://img541.imageshack.us/img541/3460/51844983.jpg

Quote:
Original post by Decrius
Or allocate dynamically, assuming you have a 32-bit system, each array takes 5000 * 10 * 4 = 200.000 bytes. There's enough of that on the heap:

float *X = new float[10 * 5000];
X[(y * 5000) + x] = 5.0f;
delete[] X;


Does that still retain the [10][5000] look? I want to be able to access it like [object][vertex] (dont know how else to explain it)

Share this post


Link to post
Share on other sites
I wouldn't change the stack size at all, allocate the array with new[] instead - then you're bound by the available address space (~2GB on a 32-bit system), not the stack size.

Share this post


Link to post
Share on other sites
Quote:
Original post by TutenStain
Does that still retain the [10][5000] look? I want to be able to access it like [object][vertex] (dont know how else to explain it)


No it doesn't. But practically you still do the same thing, basically it expands as:

X[object][vertex] -> X[(object * max_vertices) + vertex] which equals *(X + (object * max_vertices) + vertex)

So yes, you do need to remember max_vertices.

Share this post


Link to post
Share on other sites
Quote:
Original post by Decrius
Quote:
Original post by TutenStain
Does that still retain the [10][5000] look? I want to be able to access it like [object][vertex] (dont know how else to explain it)


No it doesn't. But practically you still do the same thing, basically it expands as:

X[object][vertex] -> X[(object * max_vertices) + vertex] which equals *(X + (object * max_vertices) + vertex)

So yes, you do need to remember max_vertices.


Make sense. But cant I do it this way:
float (*x)[1000] = new float[1000][1000];

Share this post


Link to post
Share on other sites
Thats not how it works. This would be right:

const int X = 1000;
const int Y = 5000;
float* Foo = new float[X*Y];

And then access it like Decrius said.

Share this post


Link to post
Share on other sites
Quote:
Original post by mind in a box
Thats not how it works. This would be right:

const int X = 1000;
const int Y = 5000;
float* Foo = new float[X*Y];

And then access it like Decrius said.



Thanks, think I got it. Will turn back here if I have any questions.

Thanks again!

Share this post


Link to post
Share on other sites
Quote:
Original post by TutenStain
Make sense. But cant I do it this way:
float (*x)[1000] = new float[1000][1000];


Yes, that will work so long as you know all but the first dimension at compile time.

int n = 10;
float (*x)[1000] = new float[n][1000]; // works
float (*y)[n] = new float[1000][n]; // doesn't work

You may also be interested in boost::array and boost::multi_array.

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!