Dune::PoolAllocator< T, s > Class Template Reference
[Common]

#include <poolallocator.hh>

List of all members.


Detailed Description

template<class T, std::size_t s>
class Dune::PoolAllocator< T, s >

An allocator managing a pool of objects for reuse.

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.

Warning:
It is not suitable for the use in standard containers as it cannot allocate arrays of arbitrary size
Template Parameters:
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...

Member Enumeration Documentation

template<class T, std::size_t s>
anonymous enum

Enumerator:
size  The number of objects to fit into one memory chunk allocated.


Member Function Documentation

template<class T, std::size_t s>
pointer Dune::PoolAllocator< T, s >::allocate ( size_t  n,
const_pointer  hint = 0 
) [inline]

Allocates objects.

Parameters:
n The number of objects to allocate. Has to be less than Pool<T,s>::elements!
hint Ignored hint.
Returns:
A pointer tp the allocated elements.

template<class T, std::size_t s>
void Dune::PoolAllocator< T, s >::construct ( pointer  p,
const_reference  value 
) [inline]

Construct an object.

Parameters:
p Pointer to the object.
value The value to initialize it to.


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

Generated on Tue Jul 28 22:27:58 2009 for dune-common by  doxygen 1.5.6