.TH alloca() "" "" "General Function (libc)"
.PC "Dynamically allocate space on the stack"
\fBalloca(\fImemory\^\fB)\fR
\fBint \fImemory\^\fB;\fR
.PP
The function
.B alloca(\^)
allocates
.I 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.
.PP
For example, consider the function:
.DM
	foo(some_string)
	char *some_string;
	{
		char *cp;
		. . .
		cp = alloca(strlen(some_string) + 1);
		strcpy(cp, some_string);
		. . .
	}
.DE
.PP
Here, the call to
.B alloca(\^)
allocates enough space upon the stack for
.B some_string
plus the terminating NUL character.
When function
.B foo(\^)
returns, the allocated memory vanishes.
.PP
This routine is popular in Berkeley and GNU circles because it
is much faster than
.BR malloc(\^) ,
and the programmer does not need to call
.B free(\^)
to de-allocate the memory.
.SH "See Also"
.Xr calloc(), calloc
.Xr libc, libc
.Xr malloc(), malloc
.Xr realloc() realloc
