fesa-core  4.3.1
fesa::Aligned< T > Class Template Reference

#include <Aligned.h>

Static Public Member Functions

static T * align (const void *memory)
 

Static Public Attributes

static const std::size_t naturalAlignment = ((sizeof(T) & (sizeof(T) - 1)) == 0) ? sizeof(T) : naturalAlignmentTemp4 + 1
 
static const std::size_t unalignedSize = naturalAlignment * 2 - 1
 

Detailed Description

template<class T>
class fesa::Aligned< T >

This class contains helper constants and methods for memory alignment purposes.

Member Function Documentation

template<typename T >
T * fesa::Aligned< T >::align ( const void *  memory)
static

From a memory address, returns another memory address which is aligned on a T's natural alignment. The returned address is greater or equal to the given address, and as close as possible to it. The result is suitable for placement new or reinterpret_cast as long as the buffer is at least unalignedSize bytes long.

Parameters
memorya memory address from which alignment will be done
Returns
a memory address aligned on T's natural alignment

Member Data Documentation

template<class T >
const std::size_t fesa::Aligned< T >::naturalAlignment = ((sizeof(T) & (sizeof(T) - 1)) == 0) ? sizeof(T) : naturalAlignmentTemp4 + 1
static

Contains the natural alignment, in bytes, of a T. For powers of 2, this is sizeof(T). For non-powers of 2, this is the next power of 2. Examples: sizeof(T) == 8 => naturalAlignment == 8. sizeof(T) == 5 => naturalAlignment == 8. sizeof(T) == 24 => naturalAlignment == 32. sizeof(T) == 32 => naturalAlignment == 32. sizeof(T) == 33 => naturalAlignment == 64.

template<class T >
const std::size_t fesa::Aligned< T >::unalignedSize = naturalAlignment * 2 - 1
static

Contains the maximum size (in bytes) that must be available to ensure natural alignment of a T. This can be used to allocate a buffer large enough to map an aligned T, even when alignment cannot be controlled.


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