0% found this document useful (0 votes)
70 views

Aligned - Alloc - Cppreference

The aligned_alloc function allocates size bytes of memory with the specified alignment. The size must be an integral multiple of alignment. It behaves as though accessing only the allocated memory locations and not static storage. A previous deallocation synchronizes with a subsequent allocation of the same memory region after the deallocation and before the new allocation. It returns a null pointer on failure or a pointer to the allocated memory, which must be freed. The alignment must be a power of two that is a multiple of sizeof(void*). Specifying an invalid size or alignment causes undefined behavior.

Uploaded by

IoakeimTziakos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Aligned - Alloc - Cppreference

The aligned_alloc function allocates size bytes of memory with the specified alignment. The size must be an integral multiple of alignment. It behaves as though accessing only the allocated memory locations and not static storage. A previous deallocation synchronizes with a subsequent allocation of the same memory region after the deallocation and before the new allocation. It returns a null pointer on failure or a pointer to the allocated memory, which must be freed. The alignment must be a power of two that is a multiple of sizeof(void*). Specifying an invalid size or alignment causes undefined behavior.

Uploaded by

IoakeimTziakos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

2/11/2014

aligned_alloc - cppreference.com

aligned_alloc
Defined in header <stdlib.h>

void *aligned_alloc( size_t alignment, size_t size );

(since C11)

Allocate sizebytes of uninitialized storage whose alignment is specified by alignment. The sizeparameter
must be an integral multiple of alignment.
aligned_allocis thread-safe: it behaves as though only accessing the memory locations visible through its
argument, and not any static storage.
A previous call to freeor reallocthat deallocates a region of memory synchronizes-with a call to
aligned_allocthat allocates the same or a part of the same region of memory. This synchronization occurs
after any access to the memory by the deallocating function and before any access to the memory by
aligned_alloc

Parameters
alignment - specifies the alignment. Must be a valid alignment supported by the implementation.
size - number of bytes to allocate. An integral multiple of alignment

Return value
Either a null pointer or a pointer to the allocated memory. The pointer must be deallocated with free().

Notes
Passing a sizewhich is not an integral multiple of alignmentor a alignmentwhich is not valid or not
supported by the implementation is undefined behavior.
E.g., the glibc requires alignmentto be a power of two and a multiple of sizeof(void *).

References
C11 standard (ISO/IEC 9899:2011):
7.22.3.1 Memory management functions

See also
C++ documentation for aligned storage
Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/memory/aligned_alloc&oldid=71402"

http://en.cppreference.com/w/c/memory/aligned_alloc

1/1

You might also like