How do i increase the size of the program stack?

L

lianne.ribeiro

I am using Visual C++ 6 IDE,with 512MB RAM. I have coded a recursive
function that has a correct end condition for recursion. There is no
infinite recursion.

For some input data,the recursive function gets called so many times
that it causes a 'First-chance exception in a.exe: 0xC00000FD: Stack
Overflow.'

How do i increase the size of the program stack?
 
R

Richard Tobin

I am using Visual C++ 6 IDE [...]
How do i increase the size of the program stack?

If you don't get an answer here, try a Microsoft newsgroup. Controlling
the stack size varies between operating systems.

-- Richard
 
R

Richard Heathfield

(e-mail address removed) said:
I am using Visual C++ 6 IDE,with 512MB RAM. I have coded a recursive
function that has a correct end condition for recursion. There is no
infinite recursion.

For some input data,the recursive function gets called so many times
that it causes a 'First-chance exception in a.exe: 0xC00000FD: Stack
Overflow.'

How do i increase the size of the program stack?

As regular readers of this newsgroup are well aware, C programs don't have
a stack. Nevertheless, the size of this non-existent stack is indeed
configurable in Visual C++ 6.

Go to the "Project" menu, and select the "Settings" submenu. You get a
tabbed dialog. Select the "Link" tab. On that tab is a dropdown menu,
entitled "Category". Pull it down and select "Output".

Now you should see a groupbox entitled "Stack Allocations", containing a
textbox entitled "Reserve". In here, put in the size (in bytes) of the
stack that you want your C program to have.

BUT! The default stack size is 1MB, which really ought to be ample
(especially for something that doesn't even exist!). If a recursive
solution doesn't fit in a meg, recursion may not be the best way to solve
the problem. Take a long, hard look at your design.

Finally - strictly speaking, your question is about an implementation
rather than the language itself, and such questions really belong in
implementation-specific newsgroups, or at least platform-specific
newsgroups. For further reference, I can thoroughly recommend
comp.os.ms-windows.programmer.win32, and you may also find the Microsoft
newsgroups to be of some use.
 
M

Malcolm McLean

I am using Visual C++ 6 IDE,with 512MB RAM. I have coded a recursive
function that has a correct end condition for recursion. There is no
infinite recursion.

For some input data,the recursive function gets called so many times
that it causes a 'First-chance exception in a.exe: 0xC00000FD: Stack
Overflow.'

How do i increase the size of the program stack?
As Richard Heathfield has pointed out, there is a way.
However a better solution is to cut down on the amount of recursion.
Take all constant parameters out of your call and put them in globals. Then
get rid of any unnecessary local variables.
If that doesn't work reduce everything to one pointer which you allocate and
deallocate with malloc().
If you need more than about nested 250,000 calls then seriously look at your
data structure and or algorithm. That looks to me like a linked list rather
than a tree.
 
J

João Jerónimo

Richard said:
As regular readers of this newsgroup are well aware, C programs don't have
a stack. Nevertheless, the size of this non-existent stack is indeed
configurable in Visual C++ 6.

It's so commonplace to have C call-chains implemented with the processor
stack that people often forget this point (me, for example!)...

JJ
 

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

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top