Reputation: 2623
im trying to create an array:
int HR[32487834];
doesn't this only take up about 128 - 130 megabytes of memory?
im using MS c++ visual studios 2005 SP1 and it crashes and tells me stack overflow.
Upvotes: 1
Views: 498
Reputation: 340168
Use a vector - the array data will be located on the heap, while you'll still get the array cleaned up automatically when you leave the function or block:
std::vector<int> HR( 32487834);
Upvotes: 11
Reputation: 347206
The stack is not that big by default. You can set the stack size with the /F compiler switch.
Without this option the stack size defaults to 1 MB. The number argument can be in decimal or C-language notation. The argument can range from 1 to the maximum stack size accepted by the linker. The linker rounds up the specified value to the nearest 4 bytes. The space between /F and number is optional.
You can also use the /STACK linker option for executables
But likely you should be splitting up your problem into parts instead of doing everything at once. Do you really need all that memory all at once?
You can usually allocate more memory on the heap than on the stack as well.
Upvotes: 3
Reputation: 26998
While your computer may have gigabytes of memory, the stack does not (by default, I think it is ~1 MB on windows, but you can make it larger).
Try allocating it on the heap with new []
.
Upvotes: 7