Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > stack overflow

Reply
Thread Tools

stack overflow

 
 
Piet L.
Guest
Posts: n/a
 
      01-15-2005
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.
 
Reply With Quote
 
 
 
 
Larry Brasfield
Guest
Posts: n/a
 
      01-15-2005
> 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<whateverTypeSuccessHad> instead of array.

> thx

Anytime.

--
--Larry Brasfield
email: http://www.velocityreviews.com/forums/(E-Mail Removed)
Above views may belong only to me.
"Piet L." <(E-Mail Removed)> wrote in message news:(E-Mail Removed) om...


 
Reply With Quote
 
 
 
 
Ioannis Vranos
Guest
Posts: n/a
 
      01-15-2005
Piet L. wrote:

> 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.




--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
Piet L.
Guest
Posts: n/a
 
      01-15-2005
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
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      01-15-2005
Piet L. wrote:

> 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




--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
Piet L.
Guest
Posts: n/a
 
      01-15-2005
it seems like my previous message didn't came true...

I want to use stacks because I need 2 dimensional arrays.
thx
 
Reply With Quote
 
Ioannis Vranos
Guest
Posts: n/a
 
      01-15-2005
Piet L. wrote:

> it seems like my previous message didn't came true...
>
> I want to use stacks because I need 2 dimensional arrays.



Did you see my reply?




--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
Larry Brasfield
Guest
Posts: n/a
 
      01-15-2005
"Piet L." <(E-Mail Removed)> wrote in message news:(E-Mail Removed) m...
> 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.

> thx

You're welcome.

--
--Larry Brasfield
email: (E-Mail Removed)
Above views may belong only to me.


 
Reply With Quote
 
rami
Guest
Posts: n/a
 
      01-17-2005
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...

 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      01-17-2005

"Piet L." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
Why stack overflow with such a small stack? Kenneth McDonald Ruby 7 09-01-2007 04:21 AM
SDM Java stack overflow Art Cisco 1 02-18-2006 07:34 PM
smart navigation gives stack overflow Mr m?ll ASP .Net 2 10-16-2004 01:09 PM
Stack overflow exception =?Utf-8?B?amJpeEBuZXdzZ3JvdXBzLm5vc3BhbQ==?= ASP .Net 5 04-22-2004 04:48 AM



Advertisments