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

Return the natural alignment for a memory block of the specified size&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
int
calculateAlignmentFromSize(std::size&lowbar;t size);
----

== Description

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;

== Return Value

natural alignment for a block of `size` bytes

== Parameters

[cols="1,4"]
|===
| Name| Description
| *size*
| size in bytes of the memory block
|===


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