BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsls::Alignment Struct Reference

#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)
 

Detailed Description

This struct provides a namespace for enumerating the set of strategies for aligning arbitrary blocks of memory.

Member Typedef Documentation

◆ MaxAlignedType

Primitive type with most stringent alignment requirement.

Deprecated:
Use AlignmentUtil::MaxAlignedType instead.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Define the minimum alignment that satisfies all types.

Deprecated:
This enum is deprecated. Use AlignmentUtil::BSLS_MAX_ALIGNMENT instead.
Enumerator
MAX_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).

Member Function Documentation

◆ 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.

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. 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

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:
Use AlignmentUtil::is2ByteAligned instead.

◆ is4ByteAligned()

bool bsls::Alignment::is4ByteAligned ( const void *  address)
inlinestatic

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:
Use AlignmentUtil::is4ByteAligned instead.

◆ 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()

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:

static const char * toAscii(Alignment::Strategy value)
@ BSLS_NATURAL
Definition bsls_alignment.h:246

will print the following on standard output:

NATURAL

The documentation for this struct was generated from the following file: