1.

Solve : Stack Overflow in C++?

Answer»

Hey guyz,

im trying to read in a FILE to a string array of size 250,000, when compiling i get an error of system.stackOverflowException.

just wondering if anyone has encountered this and can fix it.


i recieve the error when i am initializing the string array eg (string array[250000])

and i am using

while (! file.eof())
{
getline (.................etc)
}
file.close();


any help would be great

Khas1:it would help to see more of your code
2:try this
Code: [Select]static huge char *array[250000+1];
try it inside and outside your functions/classesdoesnt help

um the point of my program is to read in a file and allow the user to type in a word and it will search the database, also allowing wild cards

im using many DIFFERENT functions but the main problem is that when i debug it fails at initializing
eg

int main()
{
string array[250000];
...
..
..
}
the program wont pass there, im thinking maybe i should use a VECTOR but ive already finished the program using strings so was hoping for more ideas, thanks for the try anyway smeezekitty, i think i didnt work because im using string CLASS as opposed to char..

khaswindows, linux or dos?
are you sure its the array that is causing the stack overflow?
also some linkers you can increase the stack sizeVista and XP,

yea i run it in debug and the error appears at initializing

string array[250000];

if i reduce the size to say [2500] it will work

visual studio 2008 C++..... maybe i should use something else?you could try dev-c++
but really i dont understand because thats
less then 250K so it should allocate fine
Quote

system.stackOverflowException


this is managed code.

your trying to create 250000 object variables

that's 4 bytes for simply the pointer- or an entire megabyte of memory, just for the pointers to empty strings.

Also this exhausts the stack, since a Windows Thread is only given 1MB of Stack space.

thus your error.


what you should be doing is have a dynamically allocated array- that is, a pointer to an Array that you reallocate with Realloc() to make larger for new items.



Discussion

No Comment Found