#include <poolallocator.hh>
This allocator is specifically useful for small data types where new and delete are too expensive.
It uses a pool of memory chunks where the objects will be allocated. This means that assuming that N objects fit into memory only every N-th request for an object will result in memory allocation.
T | The type that will be allocated. | |
s | The number of elements to fit into one memory chunk. |
Public Types | |
enum | { size = s*sizeof(value_type) } |
typedef T | value_type |
Type of the values we construct and allocate. | |
typedef T * | pointer |
The pointer type. | |
typedef const T * | const_pointer |
The constant pointer type. | |
typedef T & | reference |
The reference type. | |
typedef const T & | const_reference |
The constant reference type. | |
typedef std::size_t | size_type |
The size type. | |
typedef std::ptrdiff_t | difference_type |
The difference_type. | |
typedef Pool< T, size > | PoolType |
The type of the memory pool we use. | |
Public Member Functions | |
PoolAllocator () | |
Constructor. | |
template<typename U, std::size_t u> | |
PoolAllocator (const PoolAllocator< U, u > &) | |
Coopy Constructor. | |
pointer | allocate (size_t n, const_pointer hint=0) |
Allocates objects. | |
void | deallocate (pointer p, std::size_t n) |
Free objects. | |
void | construct (pointer p, const_reference value) |
Construct an object. | |
void | destroy (pointer p) |
Destroy an object without freeing memory. | |
pointer | address (reference x) const |
Convert a reference to a pointer. | |
const_pointer | address (const_reference x) const |
Convert a reference to a pointer. | |
int | max_size () const throw () |
Not correctly implemented, yet! | |
Classes | |
struct | rebind |
Rebind the allocator to another type. More... |
anonymous enum |
pointer Dune::PoolAllocator< T, s >::allocate | ( | size_t | n, | |
const_pointer | hint = 0 | |||
) | [inline] |
Allocates objects.
n | The number of objects to allocate. Has to be less than Pool<T,s>::elements! | |
hint | Ignored hint. |
void Dune::PoolAllocator< T, s >::construct | ( | pointer | p, | |
const_reference | value | |||
) | [inline] |
Construct an object.
p | Pointer to the object. | |
value | The value to initialize it to. |