Quick Links: |
#include <bsls_alignment.h>
Classes | |
struct | Align |
Public Types | |
enum | Strategy { BSLS_MAXIMUM = 0, BSLS_NATURAL = 1, BSLS_BYTEALIGNED = 2 } |
Types of alignment strategy. More... | |
enum | { MAX_ALIGNMENT = AlignmentUtil::BSLS_MAX_ALIGNMENT } |
typedef AlignmentUtil::MaxAlignedType | MaxAlignedType |
Static Public Member Functions | |
static const char * | toAscii (Alignment::Strategy value) |
static int | calculateAlignmentFromSize (int size) |
static int | calculateAlignmentOffset (const void *address, int alignment) |
static bool | is2ByteAligned (const void *address) |
static bool | is4ByteAligned (const void *address) |
static bool | is8ByteAligned (const void *address) |
This struct
provides a namespace for enumerating the set of strategies for aligning arbitrary blocks of memory.
BSLS_MAXIMUM |
Align memory block based on the most restrictive alignment requirements of the host platform. |
BSLS_NATURAL |
Align memory block on an address that is the largest power of two that evenly divides the size (in bytes) of the block. |
BSLS_BYTEALIGNED |
Align memory block based on the least restrictive alignment requirements of the host platform (1-byte aligned). |
anonymous enum |
static const char* bsls::Alignment::toAscii | ( | Alignment::Strategy | value | ) | [static] |
Return the string representation of the specified enumerator value
. The string representation of value
matches its corresponding enumerator name with the "BSLS_" prefix elided. For example:
bsl::cout << Alignment::toAscii(Alignment::BSLS_NATURAL);
will print the following on standard output:
NATURAL
static int bsls::Alignment::calculateAlignmentFromSize | ( | int | size | ) | [static] |
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: Replaced by AlignmentUtil::calculateAlignmentFromSize
.
static int bsls::Alignment::calculateAlignmentOffset | ( | const void * | address, | |
int | alignment | |||
) | [static] |
Return the smallest non-negative offset in bytes that, when added to the specified address
, yields the specified alignment
. The behavior is undefined unless 0 < alignment
and alignment
is a power of 2.
DEPRECATED: Replaced by AlignmentUtil::calculateAlignmentOffset
.
static bool bsls::Alignment::is2ByteAligned | ( | const void * | address | ) | [static] |
Return true
if the specified address
is aligned on a 2-byte boundary (i.e., the integer value of address
is divisible by 2), and false
otherwise.
DEPRECATED: Replaced by AlignmentUtil::is2ByteAligned
.
static bool bsls::Alignment::is4ByteAligned | ( | const void * | address | ) | [static] |
Return true
if the specified address
is aligned on a 4-byte boundary (i.e., the integer value of address
is divisible by 4), and false
otherwise.
DEPRECATED: Replaced by AlignmentUtil::is4ByteAligned
.
static bool bsls::Alignment::is8ByteAligned | ( | const void * | address | ) | [static] |
Return true
if the specified address
is aligned on an 8-byte boundary (i.e., the integer value of address
is divisible by 8), and false
otherwise.
DEPRECATED: Replaced by AlignmentUtil::is8ByteAligned
.