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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stack Overflow

Status
Not open for further replies.

JohnsonGPS

Programmer
Dec 14, 2006
6
CA

I created a C++ program and defined a huge struct. The struct size is about 10000*100 bytes.

I compiled the program in Borland C++ Builder6 and everything is OK. However, Visual C++.NET 2003 reported error as "Unhandled exception at ... Stack overflow". Visual C++ will not report any problem if I reduce the struct size to a much smaller one. Anybody know how to make VC++ accept huge struct and not cause stack overflow?
Thank you in advance.

My Struct Sample:

typedef struct
{
double dVarXXX[10000];
}StructYYY;

typedef struct
{
StructYYY myStructYYY[100];
}StructZZZ;





 
I imagine you have something like this:

void SomeFunc()
{
StructZZZ Var1;
....
// do some stuff with Var1
...
return;
};

Your problem occurs because you are creating a variable that is too large for the stack, thereby causing a "stack overflow." While there should be a way to tell VC++ to create a larger stack, the more accepted method would be to create the variable using a pointer rather than on the stack, like so:

void SomeFunc()
{
// allocate memory for the var;
StructZZZ *Var1 = new(StructZZZ);
...
/* do some stuff; just remember to de-reference the structure members of Var1 with -> instead of . */
...
// remember to release the memory for the var
delete Var1;
return;
};


90% of all questions can be answer by the Help file! Try it and be amazed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top