---
name: "posix_memalign"
section: "3"
platform: "macos"
package: "Libc"
version: "1752.120.2"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/posix_memalign"
---

# posix\_memalign(3)

aligned memory allocation

## NAME

**posix\_memalign** – aligned memory allocation

## SYNOPSIS

**#include \<stdlib.h\>**

*int*\

**posix\_memalign**(*void \*\*memptr*, *size\_t alignment*, *size\_t size*);

## DESCRIPTION

The **posix\_memalign**() function allocates *size* bytes of memory such that the allocation's base address is an exact multiple of *alignment*, and returns the allocation in the value pointed to by *memptr*.

The requested *alignment* must be a power of 2 at least as large as **sizeof**(*void \**).

Memory that is allocated via **posix\_memalign**() can be used as an argument in subsequent calls to [realloc(3)](/realloc/3.md), [reallocf(3)](/reallocf/3.md), and [free(3)](/free/3.md). (Note however, that the allocation returned by [realloc(3)](/realloc/3.md) or [reallocf(3)](/reallocf/3.md) is not guaranteed to preserve the original *alignment*).

## NOTES

**posix\_memalign**() should be used judiciously as the algorithm that realizes the *alignment* constraint can incur significant memory overhead.

## RETURN VALUES

The **posix\_memalign**() function returns the value 0 if successful; otherwise it returns an error value.

## ERRORS

The **posix\_memalign**() function will fail if:

- \[EINVAL\]

  The *alignment* parameter is not a power of 2 at least as large as **sizeof**(*void \**).

- \[ENOMEM\]

  Memory allocation error.

## SEE ALSO

[free(3)](/free/3.md), [malloc(3)](/malloc/3.md), [realloc(3)](/realloc/3.md), [reallocf(3)](/reallocf/3.md), [valloc(3)](/valloc/3.md), malloc\_zone\_memalign(3)

## STANDARDS

The **posix\_memalign**() function conforms to IEEE Std 1003.1-2001 (“POSIX.1”).
