#include <bsls_alignmentutil.h>
This struct provides a namespace for a suite of compile-time constants, types, and pure procedures that provide platform-dependent alignment information.
See bsls_alignmentutil
◆ MaxAlignedType
Alias for a primitive type that has the most stringent alignment requirement.
◆ anonymous enum
| Enumerator |
|---|
| BSLS_MAX_ALIGNMENT | |
◆ calculateAlignmentFromSize()
| int bsls::AlignmentUtil::calculateAlignmentFromSize |
( |
std::size_t |
size | ) |
|
|
inlinestatic |
Return the natural alignment for a memory block of the specified size – i.e., the largest power of 2 that evenly divides size, up to a maximum of BSLS_MAX_ALIGNMENT. It is guaranteed that this alignment will be sufficient for any object having a footprint of size bytes on the current platform.
- Precondition
- The behavior is undefined unless
1 <= size and size <= INT_MAX.
- Note
- 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:
- The object may be composed entirely of elements, such as
char, that have minimal alignment restrictions, and
- The architecture and our compiler settings may result in unexpectedly lenient alignment requirements. Also note that aligning on a more restrictive boundary may improve performance.
IMPLEMENTATION NOTE
◆ calculateAlignmentOffset()
| int bsls::AlignmentUtil::calculateAlignmentOffset |
( |
const void * |
address, |
|
|
int |
alignment |
|
) |
| |
|
inlinestatic |
Return the minimum non-negative integer that, when added to the numerical value of the specified address, yields the specified alignment.
- Precondition
- The behavior is undefined unless
alignment is a positive, integral power of 2.
◆ is2ByteAligned()
| bool bsls::AlignmentUtil::is2ByteAligned |
( |
const void * |
address | ) |
|
|
inlinestatic |
Return true if the specified address is aligned on a 2-byte boundary (i.e., the numerical value of address is evenly divisible by 2), and false otherwise.
◆ is4ByteAligned()
| bool bsls::AlignmentUtil::is4ByteAligned |
( |
const void * |
address | ) |
|
|
inlinestatic |
Return true if the specified address is aligned on a 4-byte boundary (i.e., the numerical value of address is evenly divisible by 4), and false otherwise.
◆ is8ByteAligned()
| bool bsls::AlignmentUtil::is8ByteAligned |
( |
const void * |
address | ) |
|
|
inlinestatic |
Return true if the specified address is aligned on an 8-byte boundary (i.e., the numerical value of address is evenly divisible by 8), and false otherwise.
◆ isAligned()
| bool bsls::AlignmentUtil::isAligned |
( |
const void * |
address, |
|
|
std::size_t |
alignment |
|
) |
| |
|
inlinestatic |
Return true if the specified address is aligned on the specified alignment boundary (i.e., the numerical value of address is evenly divisible by alignment), and false otherwise.
- Precondition
- The behavior is undefined unless
alignment is a power of 2.
- Note
- Note that this function will
true for a null address, regardless of alignment and for a 0 alignment regardless of address.
◆ pointerAlignment()
| std::size_t bsls::AlignmentUtil::pointerAlignment |
( |
const void * |
address | ) |
|
|
inlinestatic |
Return the alignment of the specified address. Returns 0 if address is 0.
- Note
- Note that the returned value might be larger than
BSLS_MAX_ALIGNMENT.
◆ roundUpToMaximalAlignment()
| std::size_t bsls::AlignmentUtil::roundUpToMaximalAlignment |
( |
std::size_t |
size | ) |
|
|
inlinestatic |
Return the specified size (in bytes) rounded up to the smallest integral multiple of the maximum alignment.
- Precondition
- The behavior is undefined unless
0 <= size and size satisfies: size <= std::numeric_limits<std::size_t>::max()
@ BSLS_MAX_ALIGNMENT
Definition bsls_alignmentutil.h:300
◆ MaxAlignedUnion
| friend union MaxAlignedUnion |
|
friend |
The documentation for this struct was generated from the following file: