ngscopeclient 0.1-dev+51fbda87c
Classes | Public Types | Public Member Functions | List of all members
AlignedAllocator< T, alignment > Class Template Reference

Aligned memory allocator for STL containers. More...

#include <AlignedAllocator.h>

Classes

struct  rebind
 Rebind to a different type of allocator. More...
 

Public Types

typedef T * pointer
 Pointer to the allocated type.
 
typedef const T * const_pointer
 Const pointer to the allocated type.
 
typedef T & reference
 Reference to the allocated type.
 
typedef const T & const_reference
 Const reference to the allocated type.
 
typedef T value_type
 The allocated type.
 
typedef size_t size_type
 Type of the size of an allocated object.
 
typedef ptrdiff_t difference_type
 Type of the difference between two allocated pointers.
 

Public Member Functions

T * address (T &rhs)
 Get the address of an object. More...
 
const T * address (T &rhs) const
 Get the address of an object. More...
 
size_t max_size () const
 Get the max possible allocation size the allocator supports. More...
 
bool operator!= (const AlignedAllocator &other) const
 Check if two allocators are the same. More...
 
void construct (T *const p, const T &t) const
 Construct an object in-place given a reference one. More...
 
void destroy (T *const p) const
 
bool operator== (const AlignedAllocator &) const
 
 AlignedAllocator (const AlignedAllocator &)
 
template<typename U >
 AlignedAllocator (const AlignedAllocator< U, alignment > &)
 
T * allocate (size_t n) const
 Allocate a block of memory. More...
 
void deallocate (T *const p, const size_t unused) const
 Free a block of memory. More...
 
void deallocate (T *const p) const
 Free a single object. More...
 
template<typename U >
T * allocate (const size_t n, const U *const hint)
 Allocate an object. More...
 
AlignedAllocatoroperator= (const AlignedAllocator &)=delete
 

Detailed Description

template<class T, size_t alignment>
class AlignedAllocator< T, alignment >

Aligned memory allocator for STL containers.

Based on https://devblogs.microsoft.com/cppblog/the-mallocator/

Member Function Documentation

◆ address() [1/2]

template<class T , size_t alignment>
T * AlignedAllocator< T, alignment >::address ( T &  rhs)
inline

Get the address of an object.

Overloaded in case somebody overloaded the unary operator&() (which is pretty weird but the spec allows it)

Parameters
rhsThe object to get the address of

◆ address() [2/2]

template<class T , size_t alignment>
const T * AlignedAllocator< T, alignment >::address ( T &  rhs) const
inline

Get the address of an object.

Overloaded in case somebody overloaded the unary operator&() (which is pretty weird but the spec allows it)

Parameters
rhsThe object to get the address of

◆ allocate() [1/2]

template<class T , size_t alignment>
template<typename U >
T * AlignedAllocator< T, alignment >::allocate ( const size_t  n,
const U *const  hint 
)
inline

Allocate an object.

Parameters
nSize in bytes
hintIgnored

◆ allocate() [2/2]

template<class T , size_t alignment>
T * AlignedAllocator< T, alignment >::allocate ( size_t  n) const
inline

Allocate a block of memory.

Parameters
nSize in bytes (internally rounded up to our alignment)

◆ construct()

template<class T , size_t alignment>
void AlignedAllocator< T, alignment >::construct ( T *const  p,
const T &  t 
) const
inline

Construct an object in-place given a reference one.

Parameters
pDestination object
tSource object

◆ deallocate() [1/2]

template<class T , size_t alignment>
void AlignedAllocator< T, alignment >::deallocate ( T *const  p) const
inline

Free a single object.

Parameters
pObject to free

◆ deallocate() [2/2]

template<class T , size_t alignment>
void AlignedAllocator< T, alignment >::deallocate ( T *const  p,
const size_t  unused 
) const
inline

Free a block of memory.

Parameters
pBlock to free
unusedSize of block (ignored)

◆ max_size()

template<class T , size_t alignment>
size_t AlignedAllocator< T, alignment >::max_size ( ) const
inline

Get the max possible allocation size the allocator supports.

(Does not necessarily mean that we have enough RAM to do so, only enough address space)

◆ operator!=()

template<class T , size_t alignment>
bool AlignedAllocator< T, alignment >::operator!= ( const AlignedAllocator< T, alignment > &  other) const
inline

Check if two allocators are the same.

Parameters
otherThe other object

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