Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.StackOverflowException when declaring large array

Status
Not open for further replies.

ppain52

Programmer
Oct 1, 2005
1
US
Hello I am getting this message:

An unhandled exception of type 'System.StackOverflowException' occurred in test.exe

when declaring an array of strings of size 1000000. When I use the same code and make the array 10000, it works fine. Any ideas on what I can do to fix it?
 
Stacks are not an infinite resource.

There is (IIRC) some linker option to allocate a larger stack, but perhaps you should be looking at allocating space instead.

Code:
std::string foo[10000];
// replace with
std::string *foo = new std::string[10000];

--
 
Each string is 16 bytes to start with: this means you're allocating 16Mb every time. Do you really need that much?

If you are using Salem's suggestion (with two extra zeros for the million that you need instead of 10K), don't forget to deallocate otherwise you will get a Heap exception.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top