'\" t .\" Copyright 2001, John Levon .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .TH posix_memalign 3 2026-02-08 "Linux man-pages 6.18" .SH NAME posix_memalign \- allocate aligned memory .SH LIBRARY Standard C library .RI ( libc ,\~ \-lc ) .SH SYNOPSIS .nf .B #include .P .BI "int posix_memalign(void **" memptr ", size_t " alignment ", size_t " size ); .fi .P .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE .P .BR posix_memalign (): .nf _POSIX_C_SOURCE >= 200112L .fi .SH DESCRIPTION .BR posix_memalign () allocates .I size bytes and places the address of the allocated memory in .IR "*memptr" . The address of the allocated memory will be a multiple of .IR "alignment" , which must be a power of two and a multiple of .IR "sizeof(void\ *)" . This address can later be successfully passed to .BR free (3). If .I size is 0, then the value placed in .I *memptr is either NULL .\" glibc does this: or a unique pointer value. .P The memory is not zeroed. .P .BR aligned_alloc (3) is a standard function that provides the same functionality, and has a more ergonomic prototype. Use that instead. .SH RETURN VALUE .BR posix_memalign () returns zero on success, or one of the error values listed in the next section on failure. The value of .I errno is not set. .SH ERRORS .TP .B EINVAL The .I alignment argument was not a power of two, or was not a multiple of .IR "sizeof(void\ *)" . .TP .B ENOMEM Out of memory. .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ .na .nh .BR posix_memalign () T} Thread safety MT-Safe .TE .SH STANDARDS POSIX.1-2024. .SH HISTORY glibc 2.1.91. POSIX.1d, POSIX.1-2001. .SH CAVEATS On Linux (and other systems), .BR posix_memalign () does not modify .I memptr on failure. A requirement standardizing this behavior was added in POSIX.1-2008 TC2. .\" http://austingroupbugs.net/view.php?id=520 .SH SEE ALSO .BR aligned_alloc (3)