[vox-tech] dyanamic memory panacea

vox-tech@lists.lugod.org vox-tech@lists.lugod.org
Fri, 19 Jul 2002 14:11:34 -0400


On Tue, Jul 16, 2002 at 12:30:17PM -0700, Peter Jay Salzman wrote:
> the obvious advantage is that the memory is deallocated once the stack
> frame is popped.  in other words, when the function returns, all memory
> allocated by alloca is freed.  this means no memory leaks.  very cool.

  If I remember correctly alloca is used extensively inside gcc source 
code.  If this is correct you can expect it will work on any system 
you can compile gcc on.

  I found this out a few years ago when trying to compile some complex
c++ code with optimization on... g++ was calling large alloca and 
exceeding the ulimit stack size on Linux, upping the limit made it
able to compile with optimizations.


However, the man page is in error:

man alloca
# RETURN VALUE
#        The  alloca function returns a pointer to the beginning of
#        the allocated space.  If the  allocation  failed,  a  NULL
#        pointer is returned.

  alloca as implemented and tested some 6 months back has no error
indication.  If you call alloca it will always return a valid pointer
but as soon as you touch a byte beyond the available space you will
get SIGSEGV.
  I will see if I can dig up the test/bug report... if anyone is curious.