c++ question

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

singh

Golden Member
Jul 5, 2001
1,449
0
0
When you allocate an array inside a function, it is a local array, and its allocated using the stack-space. That space is limited, so when it runs out, you get an overflow. Just allocate it dynamically:

You have: double terrain1d[(divisions+1)*(divisions+1)];

Just do:
double *pTerrain1D = new double[(divisions+1)*(divisiona+1)];

Of course, use an arrow ( -> ) to access it. Other than that, its the same as what you had before.

When you're done with it, just delete it: delete pTerrain1D
 

HigherGround

Golden Member
Jan 9, 2000
1,827
0
0


<< << you can downcast the 2d array pointer to its 1d counterpart. This assumes arrays are continous in memory address space ( something you can't assume in Java for example ) >>



It is not guaranteed in C/C++ either.

>>



I didn't say it is, however it is implementation specific and armed with that knowledge one can make assumptions about the safety of such casts.