xref: /freebsd/lib/libc/stdlib/memory.3 (revision e508c3431d8e1ace6118e150837a0d0d67f1672a)
1.\" Copyright (c) 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd May 17, 2026
29.Dt MEMORY 3
30.Os
31.Sh NAME
32.Nm aligned_alloc ,
33.Nm alloca ,
34.Nm calloc ,
35.Nm free ,
36.Nm free_sized ,
37.Nm free_aligned_sized ,
38.Nm malloc ,
39.Nm posix_memalign ,
40.Nm realloc ,
41.Nm reallocf ,
42.Nm valloc ,
43.Nm mmap ,
44.Nm munmap
45.Nd memory management functions
46.Sh LIBRARY
47.Lb libc
48.Sh SYNOPSIS
49.In stdlib.h
50.Ft void *
51.Fn aligned_alloc "size_t alignment" "size_t size"
52.Ft void *
53.Fn alloca "size_t size"
54.Ft void *
55.Fn calloc "size_t nelem" "size_t elsize"
56.Ft void
57.Fn free "void *ptr"
58.Ft void
59.Fn free_sized "void *ptr" "size_t size"
60.Ft void
61.Fn free_aligned_sized "void *ptr" "size_t alignment" "size_t size"
62.Ft void *
63.Fn malloc "size_t size"
64.Ft int
65.Fn posix_memalign "void **ptr" "size_t alignment" "size_t size"
66.Ft void *
67.Fn realloc "void *ptr" "size_t size"
68.Ft void *
69.Fn reallocf "void *ptr" "size_t size"
70.Ft void *
71.Fn valloc "size_t size"
72.In sys/types.h
73.In sys/mman.h
74.Ft void *
75.Fn mmap "void * addr" "size_t len" "int prot" "int flags" "int fd" "off_t offset"
76.Ft int
77.Fn munmap "void *addr" "size_t len"
78.Sh DESCRIPTION
79These functions allocate and free memory for the calling process.
80They are described in the
81individual manual pages.
82.Sh SEE ALSO
83.Xr mmap 2 ,
84.Xr aligned_alloc 3 ,
85.Xr alloca 3 ,
86.Xr calloc 3 ,
87.Xr free 3 ,
88.Xr free_aligned_sized 3 ,
89.Xr free_sized 3 ,
90.Xr malloc 3 ,
91.Xr posix_memalign 3 ,
92.Xr realloc 3 ,
93.Xr reallocf 3 ,
94.Xr valloc 3
95.Sh STANDARDS
96The
97.Fn calloc ,
98.Fn free ,
99.Fn malloc ,
100and
101.Fn realloc
102functions conform to
103.St -isoC .
104.Pp
105The
106.Fn mmap ,
107.Fn munmap ,
108and
109.Fn posix_memalign
110functions conform to
111.St -p1003.1-2001 .
112.Pp
113The
114.Fn free_sized
115and
116.Fn free_aligned_sized
117functions conform to
118.St -isoC-2023 .
119