About stack

Brian Budge brian.budge@gmail.com
Wed Mar 8 16:09:00 GMT 2006

Hi Guillaume -

In general, stacks are limited, and usually the limit is defined by
the operating system.  On linux, you can type "limit" to see what your
current limits are.  "unlimited" means that the OS will allocate as
much as it can for your program's stack.

If you have large stack variables, and there are a lot of function
calls (recursion being a big no-no in cases like this), you will
likely run out of memory.

Why do you need it to be on the stack?  I'm guessing if you had it in
the data segment before, you don't need to worry about trampling the
memory (single thread access, no recursion), so you could allocate it
on the heap at startup, and deallocate on shutdown of your program.


On 3/8/06, Guillaume Poletto <poletto@jeuxvideo.com> wrote:
> Hello,
> I'd like to know what happens when using big local variables
> ex :
> void func () {
>  char mybuff[50000];
>  /* .. */
> }
> To avoid problems, i have been used to put instinctivly big local
> variables as 'static' in order to use data segment instead of stack. But
> now i'd like to save memory on data segment and reconsider using stack.
> Is the stack limited? Is it configurable? Does some dynamic allocation
> occurs (allocating more stack space)?
> I use gcc on PC.
> Thanks

More information about the Gcc-help mailing list