|POSIX_MEMALIGN(3P)||POSIX Programmer's Manual||POSIX_MEMALIGN(3P)|
int posix_memalign(void **memptr, size_t alignment, size_t size);
Upon successful completion, the value pointed to by memptr shall be a multiple of alignment.
If the size of the space requested is 0, the behavior is implementation-defined: either a null pointer shall be returned in memptr, or the behavior shall be as if the size were some non-zero value, except that the behavior is undefined if the the value returned in memptr is used to access an object.
The free() function shall deallocate memory that has previously been allocated by posix_memalign().
If size is 0, either:
- posix_memalign() shall not attempt to allocate any space, in which case either an implementation-defined error number shall be returned, or zero shall be returned with a null pointer returned in memptr, or
- posix_memalign() shall attempt to allocate some space and, if the allocation succeeds, zero shall be returned and a pointer to the allocated space shall be returned in memptr. The application shall ensure that the pointer is not used to access an object.
- The value of the alignment parameter is not a power of two multiple of sizeof(void *).
- There is insufficient memory available with the requested alignment.
The following sections are informative.
void *ptr = NULL; ... //do some work, which might goto error if (posix_memalign(&ptr, align, size)) goto error;
//do some more work, which might goto error ... error: free(ptr); //more cleanup;
The Base Definitions volume of POSIX.1‐2017, <stdlib.h>
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|2017||IEEE/The Open Group|