dune-common  2.2.0
Classes | Public Types | Public Member Functions
Dune::PoolAllocator< T, s > Class Template Reference

An allocator managing a pool of objects for reuse. More...

#include <dune/common/poolallocator.hh>

List of all members.

Classes

struct  rebind
 Rebind the allocator to another type. More...

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, sizePoolType
 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 (std::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!

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:
TThe type that will be allocated.
sThe number of elements to fit into one memory chunk.

Member Typedef Documentation

template<class T, std::size_t s>
typedef const T* Dune::PoolAllocator< T, s >::const_pointer

The constant pointer type.

template<class T, std::size_t s>
typedef const T& Dune::PoolAllocator< T, s >::const_reference

The constant reference type.

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

The difference_type.

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

The pointer type.

template<class T, std::size_t s>
typedef Pool<T,size> Dune::PoolAllocator< T, s >::PoolType

The type of the memory pool we use.

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

The reference type.

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

The size type.

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

Type of the values we construct and allocate.


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.


Constructor & Destructor Documentation

template<class T, std::size_t s>
template<typename U , std::size_t u>
Dune::PoolAllocator< T, s >::PoolAllocator ( const PoolAllocator< U, u > &  )
inline

Coopy Constructor.


Member Function Documentation

template<class T, std::size_t s>
pointer Dune::PoolAllocator< T, s >::address ( reference  x) const
inline

Convert a reference to a pointer.

template<class T, std::size_t s>
const_pointer Dune::PoolAllocator< T, s >::address ( const_reference  x) const
inline

Convert a reference to a pointer.

template<class T, std::size_t s>
int Dune::PoolAllocator< T, s >::max_size ( ) const throw ()
inline

Not correctly implemented, yet!


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