std::align (3) - Linux Man Pages
Defined in header <memory>
void* align( std::size_t alignment,
std::size_t size, (since C++11)
std::size_t& space );
Given a pointer ptr to a buffer of size space, returns a pointer aligned by the specified alignment for size number of bytes and decreases space argument by the number of bytes used for alignment. The first aligned address is returned.
The function modifies the pointer only if it would be possible to fit the wanted number of bytes aligned by the given alignment into the buffer. If the buffer is too small, the function does nothing and returns nullptr.
The behavior is undefined if alignment is not a power of two.
alignment - the desired alignment
size - the size of the storage to be aligned
ptr - pointer to contiguous storage of at least space bytes
space - the size of the buffer in which to operate
The adjusted value of ptr, or null pointer value if the space provided is too small.
demonstrates the use of std::align to place objects of different type in memory
// Run this code
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
LWG_2377 C++11 alignment required to be a fundamental or supported extended alignment value only need to be a power of two
alignof_operator queries alignment requirements of a type (since C++11)
alignas_specifier specifies that the storage for the variable should be aligned by specific amount (C++11)
aligned_storage defines the type suitable for use as uninitialized storage for types of given size