• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

c++ question

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.
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
 


<< << 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.
 
Back
Top