[#BloombergLP-bsls-AlignmentUtil]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bsls.adoc[bsls]::AlignmentUtil
:relfileprefix: ../../
:mrdocs:

This `struct` provides a namespace for a suite of compile&hyphen;time constants, types, and pure procedures that provide platform&hyphen;dependent alignment information&period;

== Synopsis

Declared in `&lt;bsls&lowbar;alignmentutil&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
struct AlignmentUtil;
----

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/AlignmentUtil/MaxAlignedType.adoc[`MaxAlignedType`] 
| Alias for a primitive type that has the most stringent alignment requirement&period;
|===


== Enums

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/AlignmentUtil/_04enum.adoc[`Unnamed enum`] 
| Maximum alignment supported on the current platform&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/AlignmentUtil/calculateAlignmentFromSize.adoc[`calculateAlignmentFromSize`] 
| Return the _natural_ alignment for a memory block of the specified size &hyphen;&hyphen; i&period;e&period;, the largest power of 2 that evenly divides `size`, up to a maximum of `BSLS&lowbar;MAX&lowbar;ALIGNMENT`&period; It is guaranteed that this alignment will be sufficient for any object having a footprint of `size` bytes on the current platform&period; The behavior is undefined unless `1 &lt;&equals; size` and `size &lt;&equals; INT&lowbar;MAX`&period; Note that, depending on the machine architecture and compiler setting, the returned alignment value may be more restrictive than required for a particular object for two reasons&colon; 1&period; The object may be composed entirely of elements, such as `char`, that have minimal alignment restrictions, and 2&period; The architecture and our compiler settings may result in unexpectedly lenient alignment requirements&period; Also note that aligning on a more restrictive boundary may improve performance&period;
| xref:BloombergLP/bsls/AlignmentUtil/calculateAlignmentOffset.adoc[`calculateAlignmentOffset`] 
| Return the minimum non&hyphen;negative integer that, when added to the numerical value of the specified `address`, yields the specified `alignment`&period; The behavior is undefined unless `alignment` is a positive, integral power of 2&period;
| xref:BloombergLP/bsls/AlignmentUtil/defaultAlignmentOfAlignedStorage.adoc[`defaultAlignmentOfAlignedStorage`] 
| Return the default value of the alignment argument for `std&colon;&colon;aligned&lowbar;storage` when the size argument is the specified `t&lowbar;SIZE`&period; This function is an implementation detail of BDE and should not be used elsewhere&period;
| xref:BloombergLP/bsls/AlignmentUtil/is2ByteAligned.adoc[`is2ByteAligned`] 
| Return `true` if the specified `address` is aligned on a 2&hyphen;byte boundary (i&period;e&period;, the numerical value of `address` is evenly divisible by 2), and `false` otherwise&period;
| xref:BloombergLP/bsls/AlignmentUtil/is4ByteAligned.adoc[`is4ByteAligned`] 
| Return `true` if the specified `address` is aligned on a 4&hyphen;byte boundary (i&period;e&period;, the numerical value of `address` is evenly divisible by 4), and `false` otherwise&period;
| xref:BloombergLP/bsls/AlignmentUtil/is8ByteAligned.adoc[`is8ByteAligned`] 
| Return `true` if the specified `address` is aligned on an 8&hyphen;byte boundary (i&period;e&period;, the numerical value of `address` is evenly divisible by 8), and `false` otherwise&period;
| xref:BloombergLP/bsls/AlignmentUtil/isAligned.adoc[`isAligned`] 
| Return `true` if the specified `address` is aligned on the specified `alignment` boundary (i&period;e&period;, the numerical value of `address` is evenly divisible by `alignment`), and `false` otherwise&period; The behavior is undefined unless `alignment` is a power of 2&period; Note that this function will `true` for a null `address`, regardless of `alignment` and for a 0 `alignment` regardless of `address`&period;
| xref:BloombergLP/bsls/AlignmentUtil/pointerAlignment.adoc[`pointerAlignment`] 
| Return the alignment of the specified `address`&period; Returns 0 if `address` is 0&period; Note that the returned value might be larger than `BSLS&lowbar;MAX&lowbar;ALIGNMENT`&period;
| xref:BloombergLP/bsls/AlignmentUtil/roundUpToMaximalAlignment.adoc[`roundUpToMaximalAlignment`] 
| Return the specified `size` (in bytes) rounded up to the smallest integral multiple of the maximum alignment&period; The behavior is undefined unless `0 &lt;&equals; size` and `size` satisfies&colon; &grave; size &lt;&equals; std&colon;&colon;numeric&lowbar;limits&lt;std&colon;&colon;size&lowbar;t&gt;&colon;&colon;max() &hyphen; BSLS&lowbar;MAX&lowbar;ALIGNMENT &plus; 1 &grave;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `BloombergLP::bsls::AlignmentUtil::MaxAlignedUnion`
| 
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
