Computing.Net > Forums > Programming > C++ large array size

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

C++ large array size

Reply to Message Icon

Name: Selma
Date: September 24, 2003 at 07:00:44 Pacific
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




Sponsored Link
Ads by Google

Response Number 1
Name: Maurice Reed
Date: September 24, 2003 at 07:46:15 Pacific
Reply:

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.


0

Response Number 2
Name: egkenny
Date: September 24, 2003 at 22:24:15 Pacific
Reply:

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>


0

Response Number 3
Name: Selma
Date: September 25, 2003 at 11:13:16 Pacific
Reply:

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!


0

Response Number 4
Name: Ronin1
Date: September 25, 2003 at 11:40:00 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More


Protected Mode Rotating Text in SVG



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


Sponsored links

Ads by Google


Results for: C++ large array size

Array size based on function parameter? www.computing.net/answers/programming/array-size-based-on-function-parameter/2846.html

C++ defining array size www.computing.net/answers/programming/c-defining-array-size/7913.html

Large array www.computing.net/answers/programming/large-array/19914.html