How do i increase the size of the program stack?

Discussion in 'C Programming' started by lianne.ribeiro@gmail.com, Mar 22, 2008.

  1. Guest

    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?
     
    , Mar 22, 2008
    #1
    1. Advertising

  2. In article <>,
    <> wrote:
    >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



    --
    :wq
     
    Richard Tobin, Mar 22, 2008
    #2
    1. Advertising

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

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Mar 22, 2008
    #3
  4. <> wrote in message
    >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.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
     
    Malcolm McLean, Mar 24, 2008
    #4
  5. Malcolm McLean wrote:
    > Take all constant parameters out of your call and put them in globals.


    Or declare them as static.

    JJ
     
    João Jerónimo, Mar 25, 2008
    #5
  6. Richard Heathfield wrote:
    > 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
     
    João Jerónimo, Mar 25, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raja
    Replies:
    12
    Views:
    24,438
    John Harrison
    Jun 21, 2004
  2. Ajay

    How to increase stack space/heap space

    Ajay, May 11, 2006, in forum: C Programming
    Replies:
    9
    Views:
    560
  3. Surinder Singh
    Replies:
    1
    Views:
    1,213
    Richard Bos
    Dec 20, 2007
  4. Replies:
    5
    Views:
    394
    Anand Hariharan
    Mar 23, 2008
  5. Horacius ReX

    Increase stack size in eclipse cdt

    Horacius ReX, May 7, 2008, in forum: C Programming
    Replies:
    1
    Views:
    606
    Keith Thompson
    May 7, 2008
Loading...

Share This Page