1POSIX_MEMALIGN(3P)         POSIX Programmer's Manual        POSIX_MEMALIGN(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       posix_memalign — aligned memory allocation (ADVANCED REALTIME)
13

SYNOPSIS

15       #include <stdlib.h>
16
17       int posix_memalign(void **memptr, size_t alignment, size_t size);
18

DESCRIPTION

20       The posix_memalign() function shall allocate size bytes  aligned  on  a
21       boundary  specified  by  alignment,  and  shall return a pointer to the
22       allocated memory in memptr.  The value of alignment shall be a power of
23       two multiple of sizeof(void *).
24
25       Upon  successful  completion, the value pointed to by memptr shall be a
26       multiple of alignment.
27
28       If the size of the space requested is 0, the  behavior  is  implementa‐
29       tion-defined: either a null pointer shall be returned in memptr, or the
30       behavior shall be as if the size were some non-zero value, except  that
31       the  behavior  is undefined if the the value returned in memptr is used
32       to access an object.
33
34       The free() function shall deallocate memory that  has  previously  been
35       allocated by posix_memalign().
36

RETURN VALUE

38       Upon  successful completion, posix_memalign() shall return zero; other‐
39       wise, an error number shall be returned to indicate the error  and  the
40       contents  of memptr shall either be left unmodified or be set to a null
41       pointer.
42
43       If size is 0, either:
44
45        *  posix_memalign() shall not attempt to allocate any space, in  which
46           case   either  an  implementation-defined  error  number  shall  be
47           returned, or zero shall be returned with a null pointer returned in
48           memptr, or
49
50        *  posix_memalign()  shall  attempt to allocate some space and, if the
51           allocation succeeds, zero shall be returned and a  pointer  to  the
52           allocated space shall be returned in memptr.  The application shall
53           ensure that the pointer is not used to access an object.
54

ERRORS

56       The posix_memalign() function shall fail if:
57
58       EINVAL The value of the alignment parameter is not a power of two  mul‐
59              tiple of sizeof(void *).
60
61       ENOMEM There is insufficient memory available with the requested align‐
62              ment.
63
64       The following sections are informative.
65

EXAMPLES

67       The following example shows  how  applications  can  obtain  consistent
68       behavior  on error by setting *memptr to be a null pointer before call‐
69       ing posix_memalign().
70
71
72           void *ptr = NULL;
73           ...
74           //do some work, which might goto error
75           if (posix_memalign(&ptr, align, size))
76               goto error;
77
78           //do some more work, which might goto error
79           ...
80           error:
81               free(ptr);
82               //more cleanup;
83

APPLICATION USAGE

85       The posix_memalign() function  is  part  of  the  Advisory  Information
86       option and need not be provided on all implementations.
87

RATIONALE

89       None.
90

FUTURE DIRECTIONS

92       None.
93

SEE ALSO

95       free(), malloc()
96
97       The Base Definitions volume of POSIX.1‐2017, <stdlib.h>
98
100       Portions  of  this text are reprinted and reproduced in electronic form
101       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
102       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
103       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
104       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
105       event of any discrepancy between this version and the original IEEE and
106       The  Open Group Standard, the original IEEE and The Open Group Standard
107       is the referee document. The original Standard can be  obtained  online
108       at http://www.opengroup.org/unix/online.html .
109
110       Any  typographical  or  formatting  errors that appear in this page are
111       most likely to have been introduced during the conversion of the source
112       files  to  man page format. To report such errors, see https://www.ker
113       nel.org/doc/man-pages/reporting_bugs.html .
114
115
116
117IEEE/The Open Group                  2017                   POSIX_MEMALIGN(3P)
Impressum