Debian Codegraph @

upstream/debian-unstable/man3/posix_memalign.3

raw
1 '\" t
2 .\" Copyright 2001, John Levon <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH posix_memalign 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 posix_memalign
10 \-
11 allocate aligned memory
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ,\~ \-lc )
15 .SH SYNOPSIS
16 .nf
17 .B #include <stdlib.h>
18 .P
19 .BI "int posix_memalign(void **" memptr ", size_t " alignment ", size_t " size );
20 .fi
21 .P
22 .RS -4
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
25 .RE
26 .P
27 .BR posix_memalign ():
28 .nf
29 _POSIX_C_SOURCE >= 200112L
30 .fi
31 .SH DESCRIPTION
32 .BR posix_memalign ()
33 allocates
34 .I size
35 bytes and places the address of the allocated memory in
36 .IR "*memptr" .
37 The address of the allocated memory will be a multiple of
38 .IR "alignment" ,
39 which must be a power of two and a multiple of
40 .IR "sizeof(void\ *)" .
41 This address can later be successfully passed to
42 .BR free (3).
43 If
44 .I size
45 is 0, then
46 the value placed in
47 .I *memptr
48 is either NULL
49 .\" glibc does this:
50 or a unique pointer value.
51 .P
52 The memory is not zeroed.
53 .P
54 .BR aligned_alloc (3)
55 is a standard function that provides the same functionality,
56 and has a more ergonomic prototype.
57 Use that instead.
58 .SH RETURN VALUE
59 .BR posix_memalign ()
60 returns zero on success, or one of the error values listed in the
61 next section on failure.
62 The value of
63 .I errno
64 is not set.
65 .SH ERRORS
66 .TP
67 .B EINVAL
68 The
69 .I alignment
70 argument was not a power of two, or was not a multiple of
71 .IR "sizeof(void\ *)" .
72 .TP
73 .B ENOMEM
74 Out of memory.
75 .SH ATTRIBUTES
76 For an explanation of the terms used in this section, see
77 .BR attributes (7).
78 .TS
79 allbox;
80 lbx lb lb
81 l l l.
82 Interface Attribute Value
83 T{
84 .na
85 .nh
86 .BR posix_memalign ()
87 T} Thread safety MT-Safe
88 .TE
89 .SH STANDARDS
90 POSIX.1-2024.
91 .SH HISTORY
92 glibc 2.1.91.
93 POSIX.1d, POSIX.1-2001.
94 .SH CAVEATS
95 On Linux (and other systems),
96 .BR posix_memalign ()
97 does not modify
98 .I memptr
99 on failure.
100 A requirement standardizing this behavior was added in POSIX.1-2008 TC2.
101 .\" http://austingroupbugs.net/view.php?id=520
102 .SH SEE ALSO
103 .BR aligned_alloc (3)