xref: /freebsd/share/man/man3/alloca.3 (revision 6c3a4b5f9b7bd4d4e6dc1fc2d366af99aa8fca1d)
1*6c3a4b5fSBrooks Davis.\" Copyright (c) 1980, 1991, 1993
2*6c3a4b5fSBrooks Davis.\"	The Regents of the University of California.  All rights reserved.
3*6c3a4b5fSBrooks Davis.\"
4*6c3a4b5fSBrooks Davis.\" Redistribution and use in source and binary forms, with or without
5*6c3a4b5fSBrooks Davis.\" modification, are permitted provided that the following conditions
6*6c3a4b5fSBrooks Davis.\" are met:
7*6c3a4b5fSBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
8*6c3a4b5fSBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
9*6c3a4b5fSBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
10*6c3a4b5fSBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
11*6c3a4b5fSBrooks Davis.\"    documentation and/or other materials provided with the distribution.
12*6c3a4b5fSBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
13*6c3a4b5fSBrooks Davis.\"    may be used to endorse or promote products derived from this software
14*6c3a4b5fSBrooks Davis.\"    without specific prior written permission.
15*6c3a4b5fSBrooks Davis.\"
16*6c3a4b5fSBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17*6c3a4b5fSBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*6c3a4b5fSBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*6c3a4b5fSBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20*6c3a4b5fSBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*6c3a4b5fSBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*6c3a4b5fSBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*6c3a4b5fSBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*6c3a4b5fSBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*6c3a4b5fSBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*6c3a4b5fSBrooks Davis.\" SUCH DAMAGE.
27*6c3a4b5fSBrooks Davis.\"
28*6c3a4b5fSBrooks Davis.Dd April 29, 2025
29*6c3a4b5fSBrooks Davis.Dt ALLOCA 3
30*6c3a4b5fSBrooks Davis.Os
31*6c3a4b5fSBrooks Davis.Sh NAME
32*6c3a4b5fSBrooks Davis.Nm alloca
33*6c3a4b5fSBrooks Davis.Nd memory allocator
34*6c3a4b5fSBrooks Davis.Sh SYNOPSIS
35*6c3a4b5fSBrooks Davis.In stdlib.h
36*6c3a4b5fSBrooks Davis.Ft void *
37*6c3a4b5fSBrooks Davis.Fn alloca "size_t size"
38*6c3a4b5fSBrooks Davis.Sh DESCRIPTION
39*6c3a4b5fSBrooks DavisThe
40*6c3a4b5fSBrooks Davis.Fn alloca
41*6c3a4b5fSBrooks Davisfunction
42*6c3a4b5fSBrooks Davisallocates
43*6c3a4b5fSBrooks Davis.Fa size
44*6c3a4b5fSBrooks Davisbytes of space in the stack frame of the caller.
45*6c3a4b5fSBrooks DavisThis temporary space is automatically freed on
46*6c3a4b5fSBrooks Davisreturn.
47*6c3a4b5fSBrooks Davis.Sh RETURN VALUES
48*6c3a4b5fSBrooks DavisThe
49*6c3a4b5fSBrooks Davis.Fn alloca
50*6c3a4b5fSBrooks Davisfunction returns a pointer to the beginning of the allocated space.
51*6c3a4b5fSBrooks Davis.Sh SEE ALSO
52*6c3a4b5fSBrooks Davis.Xr brk 2 ,
53*6c3a4b5fSBrooks Davis.Xr calloc 3 ,
54*6c3a4b5fSBrooks Davis.Xr getpagesize 3 ,
55*6c3a4b5fSBrooks Davis.Xr malloc 3 ,
56*6c3a4b5fSBrooks Davis.Xr realloc 3
57*6c3a4b5fSBrooks Davis.Sh HISTORY
58*6c3a4b5fSBrooks DavisThe
59*6c3a4b5fSBrooks Davis.Fn alloca
60*6c3a4b5fSBrooks Davisfunction appeared in
61*6c3a4b5fSBrooks Davis.At 32v .
62*6c3a4b5fSBrooks Davis.\" .Bx ?? .
63*6c3a4b5fSBrooks Davis.\" The function appeared in 32v, pwb and pwb.2 and in 3bsd 4bsd
64*6c3a4b5fSBrooks Davis.\" The first man page (or link to a man page that I can find at the
65*6c3a4b5fSBrooks Davis.\" moment is 4.3...
66*6c3a4b5fSBrooks Davis.Sh BUGS
67*6c3a4b5fSBrooks DavisThe
68*6c3a4b5fSBrooks Davis.Fn alloca
69*6c3a4b5fSBrooks Davisfunction
70*6c3a4b5fSBrooks Davisis machine and compiler dependent;
71*6c3a4b5fSBrooks Davisits use is discouraged.
72*6c3a4b5fSBrooks Davis.Pp
73*6c3a4b5fSBrooks DavisThe
74*6c3a4b5fSBrooks Davis.Fn alloca
75*6c3a4b5fSBrooks Davisfunction is slightly unsafe because it cannot ensure that the pointer
76*6c3a4b5fSBrooks Davisreturned points to a valid and usable block of memory.
77*6c3a4b5fSBrooks DavisThe allocation made may exceed the bounds of the stack, or even go
78*6c3a4b5fSBrooks Davisfurther into other objects in memory, and
79*6c3a4b5fSBrooks Davis.Fn alloca
80*6c3a4b5fSBrooks Daviscannot determine such an error.
81*6c3a4b5fSBrooks DavisAvoid
82*6c3a4b5fSBrooks Davis.Fn alloca
83*6c3a4b5fSBrooks Daviswith large unbounded allocations.
84