Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Allocator< T > Class Template Reference

This is a custom allocator that limits the number of mappings. More...

#include <Allocator.hxx>

Classes

union  FreeList
 List of unused elements. More...
 
struct  rebind
 typedef for allocator specialization More...
 

Public Types

typedef T value_type
 value_type required by stl
 
typedef value_typepointer
 pointer required by stl
 
typedef const value_typeconst_pointer
 const_pointer required by stl
 
typedef value_typereference
 reference required by stl
 
typedef const value_typeconst_reference
 const_reference required by stl
 
typedef std::size_t size_type
 size_type required by stl
 
typedef std::ptrdiff_t difference_type
 difference_type required by stl
 

Public Member Functions

 Allocator (size_t e)
 Constructor.
 
 Allocator (Allocator const &a)
 Copy constructor.
 
 ~Allocator ()
 Destructor.
 
template<typename U >
 Allocator (Allocator< U > const &o)
 template copy constructor.
 
T * address (T &r)
 Address of item.
 
const T * address (const T &r)
 Const address of item.
 
T * allocate (size_t cnt, const void *=0)
 Allocate item(s) out of the pool.
 
void deallocate (T *p, size_t n)
 Free itme.
 
size_t max_size () const
 Maximum number of items that can be allocated.
 
void construct (T *p, const T &t)
 Placement constructor.
 
void destroy (T *p)
 Destruct.
 
bool operator== (Allocator const &)
 Overloaded operator ==.
 
bool operator!= (Allocator const &a)
 Overloaded operator !=.
 

Public Attributes

FreeListfreeList
 Start of free list.
 
bool init
 flag that tell us if we have initilized our selves or not
 
size_t entries
 number of elements in the fixed size pool
 

Private Member Functions

 Allocator ()
 Default Constructor.
 

Detailed Description

template<typename T>
class Allocator< T >

This is a custom allocator that limits the number of mappings.

It also performs a single dynamic allocation capable of holding the total number of mappings on the first allocation request. This is so that successive allocation requests are faster, more deterministic, and don't waste memory potentially used for the heap management headers.

Definition at line 46 of file Allocator.hxx.

Member Typedef Documentation

◆ const_pointer

template<typename T >
typedef const value_type* Allocator< T >::const_pointer

const_pointer required by stl

Definition at line 68 of file Allocator.hxx.

◆ const_reference

template<typename T >
typedef const value_type& Allocator< T >::const_reference

const_reference required by stl

Definition at line 70 of file Allocator.hxx.

◆ difference_type

template<typename T >
typedef std::ptrdiff_t Allocator< T >::difference_type

difference_type required by stl

Definition at line 72 of file Allocator.hxx.

◆ pointer

template<typename T >
typedef value_type* Allocator< T >::pointer

pointer required by stl

Definition at line 67 of file Allocator.hxx.

◆ reference

template<typename T >
typedef value_type& Allocator< T >::reference

reference required by stl

Definition at line 69 of file Allocator.hxx.

◆ size_type

template<typename T >
typedef std::size_t Allocator< T >::size_type

size_type required by stl

Definition at line 71 of file Allocator.hxx.

◆ value_type

template<typename T >
typedef T Allocator< T >::value_type

value_type required by stl

Definition at line 66 of file Allocator.hxx.

Constructor & Destructor Documentation

◆ Allocator() [1/4]

template<typename T >
Allocator< T >::Allocator ( size_t  e)
inlineexplicit

Constructor.

Parameters
enumber of entries in the fixed size pool

Definition at line 84 of file Allocator.hxx.

◆ Allocator() [2/4]

template<typename T >
Allocator< T >::Allocator ( Allocator< T > const &  a)
inlineexplicit

Copy constructor.

Parameters
ainstance to copy

Definition at line 94 of file Allocator.hxx.

◆ ~Allocator()

template<typename T >
Allocator< T >::~Allocator ( )
inline

Destructor.

Definition at line 103 of file Allocator.hxx.

◆ Allocator() [3/4]

template<typename T >
template<typename U >
Allocator< T >::Allocator ( Allocator< U > const &  o)
inline

template copy constructor.

Parameters
oinsance to copy

Definition at line 110 of file Allocator.hxx.

◆ Allocator() [4/4]

template<typename T >
Allocator< T >::Allocator ( )
inlineprivate

Default Constructor.

Definition at line 216 of file Allocator.hxx.

Member Function Documentation

◆ address() [1/2]

template<typename T >
const T * Allocator< T >::address ( const T &  r)
inline

Const address of item.

Parameters
ritem to take the address of
Returns
address of item

Definition at line 130 of file Allocator.hxx.

◆ address() [2/2]

template<typename T >
T * Allocator< T >::address ( T &  r)
inline

Address of item.

Parameters
ritem to take the address of
Returns
address of item

Definition at line 121 of file Allocator.hxx.

◆ allocate()

template<typename T >
T * Allocator< T >::allocate ( size_t  cnt,
const void *  = 0 
)
inline

Allocate item(s) out of the pool.

Parameters
cntnumber of items to allocate
Returns
newly allocated item(s)

Definition at line 139 of file Allocator.hxx.

◆ construct()

template<typename T >
void Allocator< T >::construct ( T *  p,
const T &  t 
)
inline

Placement constructor.

Parameters
plocation of placement
tparameter to constructor

Definition at line 184 of file Allocator.hxx.

◆ deallocate()

template<typename T >
void Allocator< T >::deallocate ( T *  p,
size_t  n 
)
inline

Free itme.

Parameters
pitem to free
nnumber of items to free

Definition at line 164 of file Allocator.hxx.

◆ destroy()

template<typename T >
void Allocator< T >::destroy ( T *  p)
inline

Destruct.

Parameters
pitem to destruct

Definition at line 192 of file Allocator.hxx.

◆ max_size()

template<typename T >
size_t Allocator< T >::max_size ( ) const
inline

Maximum number of items that can be allocated.

Definition at line 174 of file Allocator.hxx.

◆ operator!=()

template<typename T >
bool Allocator< T >::operator!= ( Allocator< T > const &  a)
inline

Overloaded operator !=.

Parameters
aitem to compare
Returns
always false

Definition at line 209 of file Allocator.hxx.

◆ operator==()

template<typename T >
bool Allocator< T >::operator== ( Allocator< T > const &  )
inline

Overloaded operator ==.

Returns
always true.

Definition at line 200 of file Allocator.hxx.

Member Data Documentation

◆ entries

template<typename T >
size_t Allocator< T >::entries

number of elements in the fixed size pool

Definition at line 64 of file Allocator.hxx.

◆ freeList

template<typename T >
FreeList* Allocator< T >::freeList

Start of free list.

Definition at line 58 of file Allocator.hxx.

◆ init

template<typename T >
bool Allocator< T >::init

flag that tell us if we have initilized our selves or not

Definition at line 61 of file Allocator.hxx.


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