| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
C++ large array size
|
Original Message
|
Name: Selma
Date: September 24, 2003 at 07:00:44 Pacific
Subject: C++ large array size OS: Window NT CPU/Ram: 256
|
Comment: 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 was int array_a[512][512]; and it is not accepting the dimensions. Please help!! A million thanks! Selma
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Maurice Reed
Date: September 24, 2003 at 07:46:15 Pacific
|
Reply: (edit)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.
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: egkenny
Date: September 24, 2003 at 22:24:15 Pacific
|
Reply: (edit)In your situtation you might have two solutions: 1) use a gobal variable, or 2) increase the stack size Global 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>
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: Selma
Date: September 25, 2003 at 11:13:16 Pacific
|
Reply: (edit)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!
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: Ronin1
Date: September 25, 2003 at 11:40:00 Pacific
|
Reply: (edit)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.
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Programming Forum Home