This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: About stack
- From: "Brian Budge" <brian dot budge at gmail dot com>
- To: "Guillaume Poletto" <poletto at jeuxvideo dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 8 Mar 2006 08:09:46 -0800
- Subject: Re: About stack
- References: <440EF00E.1030502@jeuxvideo.com>
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.
Brian
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
>