ALLOCA(3C) ALLOCA(3C)
alloca - allocate dynamic space
#include <alloca.h>
void *alloca (unsigned size);
alloca returns a pointer to size bytes of uninitialized local stack
space. Since the space is allocated using a built-in compiler function,
the allocation is quite fast. If zero is passed as size, alloca returns
a valid pointer (unlike some versions of malloc, which consider a zero
size to be an error).
The #include <alloca.h> is required.
Space allocated when a function foo calls alloca is freed automatically
when foo returns.
It is an error to call free with a pointer returned by alloca.
Not all environments have alloca in their libraries, so code using it is
not necessarily portable. Reasonably portable public domain versions of
this function are available from various sources on the Internet and the
World Wide Web.
malloc(3), calloc(3), free(3), /usr/include/alloca.h
In this implementation alloca cannot fail (though if size makes the
process too large IRIX may kill the process). Since alloca always
returns a valid pointer, no diagnostics are possible. Portability may be
enhanced if the function calling alloca tests for a return value of 0 and
handles 0 as an error.
Do not call alloca as an argument to another function, as in
foo(alloca(20));. Instead use, for example, cp = alloca(20); foo(cp);.
PPPPaaaaggggeeee 1111 [ Back ]
|