Turbo C stack size

Mic Lacey mic at sun.soe.clarkson.edu
Sat Jul 21 02:57:11 AEST 1990


Message-ID: <1990Jul20.154753.23714 at sun.soe.clarkson.edu>
Organization: Clarkson University, Potsdam, NY
Date: 20 Jul 90 15:47:53 GMT
Lines:       41
PQ
 Andy,
     I have had the same problem with running out of stack space
using Turbo C 2.0.  I am pretty sure (but by no means positive) that
you are limited to 64k worth of stack space.  This becomes a problem
when you call functions that allocated large local variables (as these
variables are allocated on the stack when the function is called)d 
It can also be a problem if you call may functions from within functions
(this is a common problem with recusive functions).  I suspect you are
running out of space because your functions allocate too many variables
on the stack.  A possibile solution to this problem is to malloc those
large variables when the function begins (and make sure to free them
before leaving the function).  When you malloc a variable the space is
allocated off the heap, which is the space above the stack and below 
the top of memory.  Try something like this:

int  foo(int c)

{

  char  *array;


  array = (char *) malloc(SOME HUGE NUMBER);

  ...
} 

instead of:

int  foo(int c)

{
    char  array[SOME HUGE NUMBER];

    ...

}

Good luck!!



More information about the Comp.lang.c mailing list