Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

aligned_alloc(3C)

Name

aligned_alloc - aligned memory allocation

Synopsis

#include <stdlib.h>
void *aligned_alloc(size_t alignment, size_t size);

Description

The aligned_alloc() function allocates size bytes on a specified alignment boundary and returns a pointer to the allocated block.

The alignment argument must be a valid alignment, that is, any power of two (1, 2, 4, 8, ...) and the size argument must be an integral multiple of alignment.

The free(3C) function will deallocate memory that has previously been allocated by aligned_alloc().

Return Values

Upon successful completion, aligned_alloc() returns a pointer to the allocated space. Otherwise, aligned_alloc() returns a null pointer and sets errno to indicate the error.

Errors

The aligned_alloc() function will fail if:

EINVAL

The value of alignment is not a power of two, or size is not a non-zero integral multiple of alignment.

ENOMEM

There is insufficient memory available with the requested alignment.

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
MT-Safe

Notes

The aligned_alloc() function is specified in the C11 standard (INCITS/ISO/IEC 9899:2011).

See Also

free(3C), malloc(3C), memalign(3C), posix_memalign(3C), attributes(7)