Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi!
I want to have a 2D array size of [512][512]. However, my C++ program can only compile to [256][256]. Is there a reason for this? And how do I redefine my software so it accepts larger array sizes?
All I did wasint array_a[512][512];
and it is not accepting the dimensions.
Please help!!
A million thanks!
Selma

I am only guessing because I don't know which compiler and version you are using but, I suspect that it is the default 'model' that the compiler is using. An array of 256 x 256 integers comes out at 64k which is the standard stack size in the 'small' model. Whereas 512 x 512 is 256k which is too large to fit.
Look through the compiler's options and see if you can select 'large' or 'huge' as the model.

In your situtation you might have two solutions:
1) use a gobal variable, or
2) increase the stack sizeGlobal variables are created in the static data area. The space for static data is compiled into the program.
Variables in functions are created on the stack. Stack space is created dynamically at runtime. The stack size is limited by some default max value by the compiler but with the proper compile options can be increased. For example, with MS Visual C++ 6.0 the default stack size is 1 MB. This can be increased in the project setttings.
The following program shows the largest arrays I can compile in Visual C++ 6.0 using the default settings. Note that that the global variable can be larger than the one in main. The variable in the main can be made larger if I increase the stack size.
double num1[99558][99558];</br>
</br>
int main(int argc, char* argv[])</br>
{</br>
double num2[359][359];</br>
return 0;</br>
}</br>

Thank you very much! I can get a very size array through global definition now. I have another question now.
The size of my array is determined through a preceeding calculation. But the size of array can only be defined by constant integer. I tried doing static casting from integer to const integer and putting that new variable into the array dimensions, that didn't work.
Please advise : )
Thanks!

try dynamic allocation
int *myarray;
myarray = new int[new size];
Be sure to free the memory when done, and null will be returned if the allocation failed.

![]() |
Protected Mode
|
Rotating Text in SVG
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |