#include <bsls_alignment.h>
This struct provides a namespace for enumerating the set of strategies for aligning arbitrary blocks of memory.
See bsls_alignment
◆ MaxAlignedType
◆ anonymous enum
◆ Strategy
Types of alignment strategy.
| Enumerator |
|---|
| 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).
|
◆ calculateAlignmentFromSize()
| int bsls::Alignment::calculateAlignmentFromSize |
( |
int |
size | ) |
|
|
inlinestatic |
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.
- Precondition
- The behavior is undefined unless
0 < size.
- Deprecated:
- Use AlignmentUtil::calculateAlignmentFromSize instead.
◆ calculateAlignmentOffset()
| int bsls::Alignment::calculateAlignmentOffset |
( |
const void * |
address, |
|
|
int |
alignment |
|
) |
| |
|
inlinestatic |
Return the smallest non-negative offset in bytes that, when added to the specified address, yields the specified alignment.
- Precondition
- The behavior is undefined unless
0 < alignment and alignment is a power of 2.
- Deprecated:
- Use AlignmentUtil::calculateAlignmentOffset instead.
◆ is2ByteAligned()
| bool bsls::Alignment::is2ByteAligned |
( |
const void * |
address | ) |
|
|
inlinestatic |
◆ is4ByteAligned()
| bool bsls::Alignment::is4ByteAligned |
( |
const void * |
address | ) |
|
|
inlinestatic |
◆ is8ByteAligned()
| bool bsls::Alignment::is8ByteAligned |
( |
const void * |
address | ) |
|
|
inlinestatic |
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:
- Use AlignmentUtil::is8ByteAligned instead.
◆ toAscii()
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:
static const char * toAscii(Alignment::Strategy value)
@ BSLS_NATURAL
Definition bsls_alignment.h:248
will print the following on standard output:
The documentation for this struct was generated from the following file: