Re: About stack

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx> 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
>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux