473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

stack overflow error when using vector stl

Hi,
I have a structure called Tissue and I use it in a matrix like this:

vector < vector < Tissue* tissueArray(cRows);

This whole function works great for a matrix size of 2X2 to 15X15.
Beyond that it crashed with a STATUS_STACK_OVERFLOW exception!!!
1. Why does his happen?
2. How do I fix it?
3. At some point I may go to a 300X300 array. What happens then?

Thanks a lot for your time and attention!!!!!

Here are the details of my code
1.
This is the Tissue struct:
struct TissueStruct
{
TissueType type; // fibre or vessel
TissueStimulus stimulus;
TissueState state;
double tpo2;
double po2;
double deficit;
double demand;
double x;
double y;
double v;
double u;
double Iext;

};

2.
I populate the tissueArray matrix (or vector of vector of Tissue) with
a init dunction like this:

for (int i = 0; i < cRows; i++)
{
//creating a row of tissue cells
vector <Tissue*trow(cCols);
for (int j=0; j<cCols; j++)
{

if (type == Fibre)
{
trow.push_back(createFibre());
type = Vessel;
}
else
{
trow.push_back(createVessel());
// cout << "Type Vessel " << j << " " << trow[j]->type << endl;
type = Fibre;
}
}
// cout << trow.size() << endl;
tarray.push_back(trow);
}
}

3.
The createFibre and createVessel functions do the actual memory
allocation with the new keyword:

Tissue* createFibre()
{
Tissue* tissue;
tissue = new (Tissue);
tissue->type = Fibre;
tissue->po2 = Fpo2;
tissue->state = Inactive;
tissue->stimulus = Absent;
tissue->deficit = tissue->demand = 0.0;
tissue->x = tissue->y = tissue->Iext = tissue->v = tissue-u =
tissue->tpo2= 0.0;
return (tissue);
}

Sep 29 '06 #1
3 6510
"capes" <ka*********@gmail.comwrote:
Hi,
I have a structure called Tissue and I use it in a matrix like this:

vector < vector < Tissue* tissueArray(cRows);

This whole function works great for a matrix size of 2X2 to 15X15.
Beyond that it crashed with a STATUS_STACK_OVERFLOW exception!!!
1. Why does his happen?
2. How do I fix it?
3. At some point I may go to a 300X300 array. What happens then?

Thanks a lot for your time and attention!!!!!
I don't see how any of the code you posted would cause a stack overflow.
Try to post a complete, compilable example of your error.

--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer*have anyone to discuss your doubts with,
nor any ability to discuss them.
Sep 29 '06 #2
this seems to be some platform specific issue. All the local objects
are created on the stack and each os has some size allocated to the
stack. So when the number of objects that u create can no longer fit in
the stack, theoretically it can overflow and give the stack overflow
error.
u can instead try creating the objects on the heap and work with the
pointers to object rather than the objects itself.
thanks
ravinder thakur

Sep 29 '06 #3
capes wrote:
Hi,
I have a structure called Tissue and I use it in a matrix like this:

vector < vector < Tissue* tissueArray(cRows);

This whole function works great for a matrix size of 2X2 to 15X15.
Beyond that it crashed with a STATUS_STACK_OVERFLOW exception!!!
1. Why does his happen?
2. How do I fix it?
3. At some point I may go to a 300X300 array. What happens then?

Thanks a lot for your time and attention!!!!!

Here are the details of my code
1.
This is the Tissue struct:
struct TissueStruct
{
TissueType type; // fibre or vessel
TissueStimulus stimulus;
TissueState state;
double tpo2;
double po2;
double deficit;
double demand;
double x;
double y;
double v;
double u;
double Iext;

};

2.
I populate the tissueArray matrix (or vector of vector of Tissue) with
a init dunction like this:

for (int i = 0; i < cRows; i++)
{
//creating a row of tissue cells
vector <Tissue*trow(cCols);
for (int j=0; j<cCols; j++)
{

if (type == Fibre)
{
trow.push_back(createFibre());
type = Vessel;
}
else
{
trow.push_back(createVessel());
// cout << "Type Vessel " << j << " " << trow[j]->type << endl;
type = Fibre;
}
}
// cout << trow.size() << endl;
tarray.push_back(trow);
}
}

3.
The createFibre and createVessel functions do the actual memory
allocation with the new keyword:

Tissue* createFibre()
{
Tissue* tissue;
tissue = new (Tissue);
tissue->type = Fibre;
tissue->po2 = Fpo2;
tissue->state = Inactive;
tissue->stimulus = Absent;
tissue->deficit = tissue->demand = 0.0;
tissue->x = tissue->y = tissue->Iext = tissue->v = tissue-u =
tissue->tpo2= 0.0;
return (tissue);
}
Well, all your vectors store pointers, which should only
occupy a few (usually 4) bytes each. A stack's size is
usually in the order of a few MB, so you should be able
to store about a million of such pointers without a problem
(the actual data winds up on the heap, not on the stack).

Try adding some debug statements that would show how many
times the loop iterates, like

cout << "adding an element\n";

before every push_back()... perhaps it'll turn out that
your loop is infinite, that would explain the stack overflow.

HTH,
- J.
Sep 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ip4ram | last post by:
I am quite puzzled by the stack overflow which I am encountering.Here is the pseudocode //define stack structure //function operating on stack void my_stack_function( function parameters) {...
7
by: Aguilar, James | last post by:
Hello all, To begin, yes, this -is- a homework assignment. However, it is for my Algorithms class, and my instructor has given us explicit permission to use "expert" groups like newsgroups, so...
2
by: James | last post by:
Hi, I am using Visual C++ 6.0. I got a "stack overflow" error message when running the program because of a "double array". I have a computer with 1GB memory. Can I extend the memory for the...
13
by: Will Pittenger | last post by:
I have a Control derived class. When the parent of the control changes the control's Location property, the stack overflows. I have not found a way to find out what was on the stack when it does...
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
2
by: Ali | last post by:
Hi, I got stack overflow errors while using an unmanaged dll from managed c# application. When i use editbin.exe to increase stack size of app , it works. Is there a way to increase stack size of...
12
by: Geoff Cox | last post by:
Hello, Some one is getting the "stack overflow" error message when using a Javascript program which I wrote when using Internet Explorer but not when using Mozilla. Any ideas as to how I...
0
by: eternalLearner | last post by:
hi : my code creates a graph vector <Node*> node_list_vector; where class Node {
5
by: moondaddy | last post by:
I'm trying to serialize some xaml elements using the XamlWriter and I'm getting a stack overflow error because the elements have some public properties which get called about a million ( a lot)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.