stack depth problem

P

PJ6

I have an algorithm that processes data recursively. When I'm testing it
works fine, but when I feed it data from the actual application, I get
"stack overflow". What bothers me is that the data my recursive processor is
seeing in production is identical to the test data; the only difference is
that now the processor must go deeper into an object model to get the values
with which it is working. I trace things through, there is no out of control
recursion. I've never seen this before, but the stack just craps out on a
legitimate path of execution. Not enough room. Before I rewrite my
processor, I'd like to know, is there a way of increasing stack depth?

I'm probably going to have dump the recursion since data can change... so
this question is more academic than anything else.

Paul
 
W

William DePalo [MVP VC++]

PJ6 said:
I have an algorithm that processes data recursively. When I'm testing it
works fine, but when I feed it data from the actual application, I get
"stack overflow". What bothers me is that the data my recursive processor
is seeing in production is identical to the test data; the only difference
is that now the processor must go deeper into an object model to get the
values with which it is working. I trace things through, there is no out of
control recursion. I've never seen this before, but the stack just craps
out on a legitimate path of execution. Not enough room. Before I rewrite my
processor, I'd like to know, is there a way of increasing stack depth?

Yes, there is. You can use the STACKSIZE in a module definition file or the
/STACK:n where n is the size in bytes of the maximum amount of stack you
expect to use.

Regards,
Will
 
C

Carl Daniel [VC++ MVP]

PJ6 said:
I have an algorithm that processes data recursively. When I'm testing
it works fine, but when I feed it data from the actual application, I
get "stack overflow". What bothers me is that the data my recursive
processor is seeing in production is identical to the test data; the
only difference is that now the processor must go deeper into an
object model to get the values with which it is working. I trace
things through, there is no out of control recursion. I've never seen
this before, but the stack just craps out on a legitimate path of
execution. Not enough room. Before I rewrite my processor, I'd like
to know, is there a way of increasing stack depth?
I'm probably going to have dump the recursion since data can
change... so this question is more academic than anything else.

You can increase the stack size for any threads that you create by passing a
larger stack size to CreateThread (or _beginthreadex). For the main entry
point of the application, you can increase the stack size using the linker
option /STACK:size_in_bytes when the EXE is linked (or with the STACKSIZE
directive in a .DEF file, or by using EDITBIN on the EXE after linking).
Note that if you're not building the EXE, the only recourse you have is to
create a new thread with the larger size.

I'd agree though - if you're using up a 1Mb stack, you probably need to
think about a non-recursive approach.

-cd
 

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

Top