COHERENT manpages

This page displays the COHERENT manpage for alloca() [Dynamically allocate space on the stack].

List of available manpages
Index


alloca() -- General Function (libc)

Dynamically allocate space on the stack
alloca(memory)
int memory;

The function alloca() allocates  memory number of bytes  dynamically on the
stack.   The  allocated  memory disappears  automatically  as  soon as  the
program exits from the function within which the memory was allocated.

For example, consider the function:

    foo(some_string)
    char *some_string;
    {
        char *cp;
        . . .
        cp = alloca(strlen(some_string) + 1);
        strcpy(cp, some_string);
        . . .
    }

Here, the call to alloca()  allocates  enough  space  upon  the  stack  for
some_string plus the terminating NUL character.  When function foo()
returns, the allocated memory vanishes.

This routine  is popular  in Berkeley  and GNU circles  because it  is much
faster than malloc(), and the programmer does not need to call free()    to
de-allocate the memory.

See Also

calloc(),
libc,
malloc(),
realloc()