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

Calculate a usable alignment for an object of the specified `size`&period;

== Synopsis

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

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

== Description

Calculate a usable alignment for an object of specified `size` bytes in the absence of compile&hyphen;time knowledge of the object&apos;s alignment requirements&period; Return the largest power of two that evenly divides size, up to a maximum of `MAX&lowbar;ALIGNMENT`&period; It is guaranteed that an object of `size` bytes can be safely aligned on this return value&period; Depending on the machine architecture and compiler options, the returned alignment may be more than required for two reasons&colon; &grave; 1&period; The object may be composed entirely of elements, such as &apos;char&apos;, which have minimal alignment restrictions&period;

2&period; The architecture may have lenient alignment requirements&period; Even if this is the case, aligning on a stricter boundary may improve performance&period; &grave; The behavior is undefined unless `0 &lt; size`&period;

DEPRECATED&colon; Use `AlignmentUtil&colon;&colon;calculateAlignmentFromSize` instead&period;

== Return Value

largest power of two that evenly divides `size`, up to `MAX&lowbar;ALIGNMENT`

== Parameters

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


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