Alloca Wars: Another View

James Buster bitbug at vsi1
Tue Aug 9 07:03:56 AEST 1988


There is one reason to use alloca: longjmp. Code in which it is
possible to longjmp out of may not work when using malloc as
the memory allocator of choice, since the corresponding free
may never be called, wasting memory and perhaps causing your
program to crash. Longjmp works by restoring a previous stack
frame, and deleting the present one (which includes any memory
allocated by alloca). Thus, programs which tend to use longjmp
a lot (shells, text editors, etc) will probably work better and
more reliably with alloca than malloc.
-- 
-- 



More information about the Comp.lang.c mailing list