alloca() portability
Paul Beusterien
paulb at ssd.csd.harris.com
Tue Nov 13 05:13:57 AEST 1990
In article <27608 at mimsy.umd.edu> Chris Torek writes :
> It is rather circular, but the circle exists now and as a result it is
> hard to break out of it. In my opinion, when breaking such a circle it
> is best to do so cleanly, and (also my opinion) alloca is *not* clean.
In my opinion alloca is the cleanest way to allocate memory that is needed
for the lifetime of a single routine. Why go to the trouble of allocating
memory from a generic place when it can be associated with the routine
that uses it?
There can be major time and space gains by using alloca instead of malloc
and free. It is obviously faster to adjust a stack pointer than to search
an available list and free it back up. Also, space may be saved because
of less fragmentation. If another routine has already alloca'ed space or
there has been a lot of recursion in some other place in the program, the
alloca may be completely free because the stack space has already been
allocated.
--
Paul Beusterien paulb at ssd.csd.harris.com
Harris Computer Systems {uunet,mit-eddie,novavax}!hcx1!paulb
Ft. Lauderdale, FL voice: (305) 973 5270
More information about the Comp.lang.c
mailing list