stack overflow

P

Piet L.

hey,

I have a program where you can set different parameters.
One of the parameters is Nr_Of_Runs.
This number will then be used in an array:
success[Nr_Of_Runs].
It works with Nr_Of_Runs <= 5000
But if I what to do more runs, I get a stack overflow.
Can someone help?

thx

PL.
 
L

Larry Brasfield

hey,
Yo, dude.
I have a program where you can set different parameters.
One of the parameters is Nr_Of_Runs.
This number will then be used in an array:
success[Nr_Of_Runs].
It works with Nr_Of_Runs <= 5000
But if I what to do more runs, I get a stack overflow.
Can someone help?

Use std::vector said:
Anytime.
 
I

Ioannis Vranos

Piet said:
hey,

I have a program where you can set different parameters.
One of the parameters is Nr_Of_Runs.
This number will then be used in an array:
success[Nr_Of_Runs].
It works with Nr_Of_Runs <= 5000
But if I what to do more runs, I get a stack overflow.
Can someone help?

Stack has limited space. Use std::vector instead of built in arrays.
 
P

Piet L.

Yes,
but I also want to use dimensional arrays.
How about that?
Can't I extend my memory use or so?
I'm using Windows XP, and have a memory of 1024
 
I

Ioannis Vranos

Piet said:
Yes,
but I also want to use dimensional arrays.
How about that?
Can't I extend my memory use or so?
I'm using Windows XP, and have a memory of 1024


I do not know whose message you replied to, however you can use vectors
for multi-dimensional arrays. Here is a two-dimensional 30x20 vector of
ints, all initialised to 0:


#include <vector>


int main()
{
using namespace std;

vector<vector<int> >array(30, vector<int>(20));
}



Notice the space, between the two '>'s. If you place them together, the
compiler may get confuse it with the operator >> (bitwise or whatever)
and produce an error.



Basically, what you need to do is to read a good up to date ISO C++
book. If you have some programming background in any language, a good
choice is "Accelerated C++" by Andrew Koenig, Barbara Moo:

http://www.acceleratedcpp.com
 
P

Piet L.

it seems like my previous message didn't came true...

I want to use stacks because I need 2 dimensional arrays.
thx
 
L

Larry Brasfield

Piet L. said:
it seems like my previous message didn't came true...

I want to use stacks because I need 2 dimensional arrays.

That is a non-sequitur. You can create 2D arrays either
on the stack or elsewhere. For your arrays that blow
the default stack limit, unless you do nothing with them
the time needed to dynamically allocate it will be small
compared to the time spent manipulating it. So the
advice Mr. Vranos and I have tendered stands: Use
std::vector, which will handle the detail of dynamic array
allocation for you and act very much like an array.

Alternatively, consult the documentation for the compiler
and/or linker that you use so that you can set a stack size
limit appropriate to your 2D array created on the stack.
Just how to do that is off-topic here.
You're welcome.
 
R

rami

if this is just test program you can tune the stack size in your
complier options and if for production better switch to heap based
memory allocation...
 
H

Howard

Piet L. said:
hey,

I have a program where you can set different parameters.
One of the parameters is Nr_Of_Runs.
This number will then be used in an array:
success[Nr_Of_Runs].
It works with Nr_Of_Runs <= 5000
But if I what to do more runs, I get a stack overflow.
Can someone help?

thx

PL.

I don't see how you can be using a variable sized array but getting stack
errors? If you dynamically allocate an array (using "new"), then it's going
into the "free store" (heap), not the stack. On the other hand, if you're
simply declaring the array with a constant size, then I fail to see how
you're using Nr_Of_Runs, since it needs to be a compile-time-constant, and
the ability to set it tends to imply you're allocating the array
dynamically. How about some code that demonstrates the problem?
-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top