##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# aligned_alloc

From cppreference.com
< c‎ | memory

Defined in header `<stdlib.h>` |  |
void *aligned_alloc( size_t alignment, size_t size ); |  | (since C11)

Allocate `size` bytes of uninitialized storage whose alignment is specified by `alignment`. The `size` parameter should be an integral multiple of `alignment`.

### [edit] Parameters

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

### [edit] Return value

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

### [edit] Notes

Passing a `size` which is not an integral multiple of `alignment` or a `alignment` which is not valid or not supported by the implementation is undefined behavior (See J.2 in C11).

E.g., the glibc requires `alignment` to be a power of two and a multiple of `sizeof(void *)`.

### [edit] References

- C11 standard (ISO/IEC 9899:2011):

  - 7.22.3.1 Memory management functions

### [edit] See also

C++ documentation for aligned storage

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/memory/aligned_alloc&oldid=66080"