CppCommon  1.0.4.1
C++ Common Library
Classes | Public Types | Public Member Functions | Friends | List of all members
CppCommon::Allocator< T, TMemoryManager, nothrow > Class Template Reference

Memory allocator class. More...

#include <allocator.h>

Classes

struct  rebind
 Rebind allocator. More...
 

Public Types

typedef T value_type
 Element type. More...
 
typedef T * pointer
 Pointer to element. More...
 
typedef T & reference
 Reference to element. More...
 
typedef const T * const_pointer
 Pointer to constant element. More...
 
typedef const T & const_reference
 Reference to constant element. More...
 
typedef size_t size_type
 Quantities of elements. More...
 
typedef ptrdiff_t difference_type
 Difference between two pointers. More...
 

Public Member Functions

 Allocator (TMemoryManager &manager) noexcept
 Initialize allocator with a given memory manager. More...
 
template<typename U >
 Allocator (const Allocator< U, TMemoryManager, nothrow > &alloc) noexcept
 
 Allocator (const Allocator &alloc) noexcept
 
 Allocator (Allocator &&) noexcept=default
 
 ~Allocator () noexcept=default
 
template<typename U >
Allocatoroperator= (const Allocator< U, TMemoryManager, nothrow > &alloc) noexcept
 
Allocatoroperator= (const Allocator &alloc) noexcept
 
Allocatoroperator= (Allocator &&) noexcept=default
 
pointer address (reference x) const noexcept
 Get the address of the given reference. More...
 
const_pointer address (const_reference x) const noexcept
 Get the constant address of the given constant reference. More...
 
size_type max_size () const noexcept
 Get the maximum number of elements, that could potentially be allocated by the allocator. More...
 
pointer allocate (size_type num, const void *hint=0)
 Allocate a block of storage suitable to contain the given count of elements. More...
 
void deallocate (pointer ptr, size_type num)
 Release a block of storage previously allocated. More...
 
void reset ()
 Reset the allocator. More...
 
template<typename U , class... Args>
void construct (U *ptr, Args &&... args)
 Constructs an element object on the given location pointer. More...
 
template<typename U >
void destroy (U *ptr)
 Destroys in-place the object pointed by the given location pointer. More...
 
template<class... Args>
T * Create (Args &&... args)
 Create a single element object. More...
 
void Release (T *ptr)
 Release a single element object. More...
 
template<class... Args>
T * CreateArray (size_t length, Args &&... args)
 Create an array of element objects. More...
 
void ReleaseArray (T *ptr)
 Release an array of element objects. More...
 

Friends

template<typename U , class UMemoryManager , bool flag>
class Allocator
 

Detailed Description

template<typename T, class TMemoryManager, bool nothrow = false>
class CppCommon::Allocator< T, TMemoryManager, nothrow >

Memory allocator class.

Memory allocator implements standard allocator interface and wraps the memory manager provided as a template argument.

Not thread-safe.

Examples
memory_arena.cpp, and memory_pool.cpp.

Definition at line 24 of file allocator.h.

Member Typedef Documentation

◆ const_pointer

template<typename T , class TMemoryManager , bool nothrow = false>
typedef const T* CppCommon::Allocator< T, TMemoryManager, nothrow >::const_pointer

Pointer to constant element.

Definition at line 37 of file allocator.h.

◆ const_reference

template<typename T , class TMemoryManager , bool nothrow = false>
typedef const T& CppCommon::Allocator< T, TMemoryManager, nothrow >::const_reference

Reference to constant element.

Definition at line 39 of file allocator.h.

◆ difference_type

template<typename T , class TMemoryManager , bool nothrow = false>
typedef ptrdiff_t CppCommon::Allocator< T, TMemoryManager, nothrow >::difference_type

Difference between two pointers.

Definition at line 43 of file allocator.h.

◆ pointer

template<typename T , class TMemoryManager , bool nothrow = false>
typedef T* CppCommon::Allocator< T, TMemoryManager, nothrow >::pointer

Pointer to element.

Definition at line 33 of file allocator.h.

◆ reference

template<typename T , class TMemoryManager , bool nothrow = false>
typedef T& CppCommon::Allocator< T, TMemoryManager, nothrow >::reference

Reference to element.

Definition at line 35 of file allocator.h.

◆ size_type

template<typename T , class TMemoryManager , bool nothrow = false>
typedef size_t CppCommon::Allocator< T, TMemoryManager, nothrow >::size_type

Quantities of elements.

Definition at line 41 of file allocator.h.

◆ value_type

template<typename T , class TMemoryManager , bool nothrow = false>
typedef T CppCommon::Allocator< T, TMemoryManager, nothrow >::value_type

Element type.

Definition at line 31 of file allocator.h.

Constructor & Destructor Documentation

◆ Allocator() [1/4]

template<typename T , class TMemoryManager , bool nothrow = false>
CppCommon::Allocator< T, TMemoryManager, nothrow >::Allocator ( TMemoryManager &  manager)
inlineexplicitnoexcept

Initialize allocator with a given memory manager.

Parameters
manager- Memory manager

Definition at line 49 of file allocator.h.

◆ Allocator() [2/4]

template<typename T , class TMemoryManager , bool nothrow = false>
template<typename U >
CppCommon::Allocator< T, TMemoryManager, nothrow >::Allocator ( const Allocator< U, TMemoryManager, nothrow > &  alloc)
inlinenoexcept

Definition at line 51 of file allocator.h.

◆ Allocator() [3/4]

template<typename T , class TMemoryManager , bool nothrow = false>
CppCommon::Allocator< T, TMemoryManager, nothrow >::Allocator ( const Allocator< T, TMemoryManager, nothrow > &  alloc)
inlinenoexcept

Definition at line 52 of file allocator.h.

◆ Allocator() [4/4]

template<typename T , class TMemoryManager , bool nothrow = false>
CppCommon::Allocator< T, TMemoryManager, nothrow >::Allocator ( Allocator< T, TMemoryManager, nothrow > &&  )
defaultnoexcept

◆ ~Allocator()

template<typename T , class TMemoryManager , bool nothrow = false>
CppCommon::Allocator< T, TMemoryManager, nothrow >::~Allocator ( )
defaultnoexcept

Member Function Documentation

◆ address() [1/2]

template<typename T , class TMemoryManager , bool nothrow = false>
const_pointer CppCommon::Allocator< T, TMemoryManager, nothrow >::address ( const_reference  x) const
inlinenoexcept

Get the constant address of the given constant reference.

Parameters
x- Constant reference to the element
Returns
Constant pointer to the element

Definition at line 74 of file allocator.h.

◆ address() [2/2]

template<typename T , class TMemoryManager , bool nothrow = false>
pointer CppCommon::Allocator< T, TMemoryManager, nothrow >::address ( reference  x) const
inlinenoexcept

Get the address of the given reference.

Parameters
x- Reference to the element
Returns
Pointer to the element

Definition at line 68 of file allocator.h.

◆ allocate()

template<typename T , class TMemoryManager , bool nothrow>
T * CppCommon::Allocator< T, TMemoryManager, nothrow >::allocate ( size_type  num,
const void *  hint = 0 
)
inline

Allocate a block of storage suitable to contain the given count of elements.

Parameters
num- Number of elements to be allocated
hint- Allocation hint (default is 0)
Returns
A pointer to the initial element in the block of storage

Definition at line 29 of file allocator.inl.

◆ construct()

template<typename T , class TMemoryManager , bool nothrow>
template<typename U , class... Args>
void CppCommon::Allocator< T, TMemoryManager, nothrow >::construct ( U *  ptr,
Args &&...  args 
)
inline

Constructs an element object on the given location pointer.

Parameters
ptr- Pointer to a location with enough storage space to contain an element
args- Arguments to initialize the construced element with

Definition at line 50 of file allocator.inl.

◆ Create()

template<typename T , class TMemoryManager , bool nothrow>
template<class... Args>
T * CppCommon::Allocator< T, TMemoryManager, nothrow >::Create ( Args &&...  args)
inline

Create a single element object.

Parameters
args- Arguments to initialize the construced element with
Examples
memory_arena.cpp, and memory_pool.cpp.

Definition at line 72 of file allocator.inl.

◆ CreateArray()

template<typename T , class TMemoryManager , bool nothrow>
template<class... Args>
T * CppCommon::Allocator< T, TMemoryManager, nothrow >::CreateArray ( size_t  length,
Args &&...  args 
)
inline

Create an array of element objects.

Parameters
length- Length of the array
args- Arguments to initialize the construced element with
Examples
memory_arena.cpp, and memory_pool.cpp.

Definition at line 102 of file allocator.inl.

◆ deallocate()

template<typename T , class TMemoryManager , bool nothrow>
void CppCommon::Allocator< T, TMemoryManager, nothrow >::deallocate ( pointer  ptr,
size_type  num 
)
inline

Release a block of storage previously allocated.

Parameters
ptr- Pointer to a block of storage
num- Number of releasing elements

Definition at line 43 of file allocator.inl.

◆ destroy()

template<typename T , class TMemoryManager , bool nothrow>
template<typename U >
void CppCommon::Allocator< T, TMemoryManager, nothrow >::destroy ( U *  ptr)
inline

Destroys in-place the object pointed by the given location pointer.

Parameters
ptr- Pointer to the object to be destroyed

Definition at line 61 of file allocator.inl.

◆ max_size()

template<typename T , class TMemoryManager , bool nothrow = false>
size_type CppCommon::Allocator< T, TMemoryManager, nothrow >::max_size ( ) const
inlinenoexcept

Get the maximum number of elements, that could potentially be allocated by the allocator.

Returns
The number of elements that might be allocated as maximum by a call to the allocate() method

Definition at line 80 of file allocator.h.

◆ operator=() [1/3]

template<typename T , class TMemoryManager , bool nothrow = false>
Allocator& CppCommon::Allocator< T, TMemoryManager, nothrow >::operator= ( Allocator< T, TMemoryManager, nothrow > &&  )
defaultnoexcept

◆ operator=() [2/3]

template<typename T , class TMemoryManager , bool nothrow = false>
Allocator& CppCommon::Allocator< T, TMemoryManager, nothrow >::operator= ( const Allocator< T, TMemoryManager, nothrow > &  alloc)
inlinenoexcept

Definition at line 59 of file allocator.h.

◆ operator=() [3/3]

template<typename T , class TMemoryManager , bool nothrow = false>
template<typename U >
Allocator& CppCommon::Allocator< T, TMemoryManager, nothrow >::operator= ( const Allocator< U, TMemoryManager, nothrow > &  alloc)
inlinenoexcept

Definition at line 57 of file allocator.h.

◆ Release()

template<typename T , class TMemoryManager , bool nothrow>
void CppCommon::Allocator< T, TMemoryManager, nothrow >::Release ( T *  ptr)
inline

Release a single element object.

Parameters
ptr- Pointer to the object to be released
Examples
memory_arena.cpp, and memory_pool.cpp.

Definition at line 85 of file allocator.inl.

◆ ReleaseArray()

template<typename T , class TMemoryManager , bool nothrow>
void CppCommon::Allocator< T, TMemoryManager, nothrow >::ReleaseArray ( T *  ptr)
inline

Release an array of element objects.

Parameters
ptr- Pointer to the object to be released
Examples
memory_arena.cpp, and memory_pool.cpp.

Definition at line 124 of file allocator.inl.

◆ reset()

template<typename T , class TMemoryManager , bool nothrow = false>
void CppCommon::Allocator< T, TMemoryManager, nothrow >::reset ( )
inline

Reset the allocator.

Definition at line 97 of file allocator.h.

Friends And Related Function Documentation

◆ Allocator

template<typename T , class TMemoryManager , bool nothrow = false>
template<typename U , class UMemoryManager , bool flag>
friend class Allocator
friend

Definition at line 27 of file allocator.h.


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