Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/memory/align"

From cppreference.com
< cpp‎ | memory
(See also: link to language)
m (Text replace - "/sidebar" to "/navbar")
Line 1: Line 1:
 
{{cpp/title|align}}
 
{{cpp/title|align}}
{{cpp/memory/sidebar}}
+
{{cpp/memory/navbar}}
 
{{ddcl | notes={{mark since c++11}} | header=memory |  
 
{{ddcl | notes={{mark since c++11}} | header=memory |  
 
void* align( std::size_t alignment,
 
void* align( std::size_t alignment,

Revision as of 13:27, 15 June 2012

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
Dynamic memory management
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Allocators
Garbage collection support
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)



 
Defined in header <memory>
void* align( std::size_t alignment,

             std::size_t size,
             void*& ptr,

             std::size_t& space);
(since C++11)

If it is possible to fit size bytes of storage aligned by alignment into the buffer pointed to by ptr with length space, the function modifies ptr to point to the first possible address of such aligned storage and decreases space by the number of bytes used for alignment. If it is impossible (the buffer is too small), align does nothing.

Contents

Parameters

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

Return value

The adjusted value of ptr, or null pointer value if the space provided is too small.

Example

See also

Template:cpp/language/dcl list alignofTemplate:cpp/language/dcl list alignas
(C++11)(deprecated in C++23)
defines the type suitable for use as uninitialized storage for types of given size
(class template) [edit]