BloombergLP::bsls::Alignment::calculateAlignmentFromSize

Calculate a usable alignment for an object of the specified size.

Synopsis

Declared in <bsls_alignment.h>

static
int
calculateAlignmentFromSize(int size);

Description

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

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

DEPRECATED: Use AlignmentUtil::calculateAlignmentFromSize instead.

Return Value

largest power of two that evenly divides size, up to MAX_ALIGNMENT

Parameters

NameDescription
sizesize in bytes of the object