Quick Links:

bal | bbl | bdl | bsl

Classes | Public Types | Static Public Member Functions | Friends

bsls::AlignmentUtil Struct Reference

#include <bsls_alignmentutil.h>

List of all members.

Classes

union  MaxAlignedUnion

Public Types

enum  { BSLS_MAX_ALIGNMENT = AlignmentFromType<MaxAlignedUnion>::VALUE }
typedef AlignmentToType
< BSLS_MAX_ALIGNMENT >::Type 
MaxAlignedType

Static Public Member Functions

static int calculateAlignmentFromSize (std::size_t 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)
static std::size_t roundUpToMaximalAlignment (std::size_t size)

Friends

union MaxAlignedUnion

Detailed Description

This struct provides a namespace for a suite of compile-time constants, types, and pure procedures that provide platform-dependent alignment information.

See Component bsls_alignmentutil


Member Typedef Documentation

typedef AlignmentToType<BSLS_MAX_ALIGNMENT>::Type bsls::AlignmentUtil::MaxAlignedType

Member Enumeration Documentation

anonymous enum

Define the minimal value that satisfies the alignment requirements for all types.

Enumerator:
BSLS_MAX_ALIGNMENT 

Member Function Documentation

static int bsls::AlignmentUtil::calculateAlignmentFromSize ( std::size_t  size  )  [static]

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. The behavior is undefined unless 1 <= size and size <= INT_MAX. 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:

  1. The object may be composed entirely of elements, such as char, that have minimal alignment restrictions, and
  2. 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.

static int bsls::AlignmentUtil::calculateAlignmentOffset ( const void *  address,
int  alignment 
) [static]

Return the minimum non-negative integer that, when added to the numerical value of the specified address, yields the specified alignment. The behavior is undefined unless alignment is a positive, integral power of 2.

static bool bsls::AlignmentUtil::is2ByteAligned ( const void *  address  )  [static]

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.

static bool bsls::AlignmentUtil::is4ByteAligned ( const void *  address  )  [static]

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.

static bool bsls::AlignmentUtil::is8ByteAligned ( const void *  address  )  [static]

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.

static std::size_t bsls::AlignmentUtil::roundUpToMaximalAlignment ( std::size_t  size  )  [static]

Return the specified size (in bytes) rounded up to the smallest integral multiple of the maximum alignment. The behavior is undefined unless 0 <= size and size satisfies:

          size <= std::numeric_limits<std::size_t>::max()
                  - BSLS_MAX_ALIGNMENT + 1

Friends And Related Function Documentation

friend union MaxAlignedUnion [friend]

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