alloca
Doug Gwyn
gwyn at smoke.BRL.MIL
Sun Apr 23 11:37:59 AEST 1989
In article <8261 at chinet.chi.il.us> les at chinet.chi.il.us (Leslie Mikesell) writes:
>Now, why can't the machines that can dynamically allocate space off the
>stack have an ordinary alloca() and those that can't provide a fake one
>which uses malloc() but tags the blocks such that calling alloca() or
>malloc() again will automatically free() any blocks alloca()'ed from
>a function that is no longer active?
That's indeed more or less how my alloca() emulation works, but there are
numerous practical details that have to be taken care of, and such an
emulation simply cannot do the "right thing" under all circumstances.
Having gone through the exercise, I can assure you that alloca() is not a
good idea in C as it exists. Some similar functionality might be useful
in a new programming language design (not C). In writing many hundreds of
thousands of lines of C source code, I've never felt a strong enough need
for alloca() to cause me to use it. Normally when I dynamically allocate
storage, it needs to hang around after the scope of the function in which
it was allocated terminates. When it doesn't, normally automatic variables
suffice. The few remaining instances aren't a great deal of trouble and
I use malloc()/free() for those.
More information about the Comp.unix.wizards
mailing list