Dune Core Modules (2.9.0)

Dune::PoolAllocator< T, s > Class Template Reference

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

#include <dune/common/poolallocator.hh>

Classes

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

Public Types

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 > &)
 Copy Constructor that does not copy the memory pool.
 
 PoolAllocator (const PoolAllocator &)
 Copy constructor that does not copy the memory pool.
 
pointer allocate (std::size_t n, const_pointer hint=0)
 Allocates objects. More...
 
void deallocate (pointer p, std::size_t n)
 Free objects. More...
 
void construct (pointer p, const_reference value)
 Construct an object. More...
 
void destroy (pointer p)
 Destroy an object without freeing memory. More...
 
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 noexcept
 Not correctly implemented, yet!
 

Static Public Attributes

static constexpr int size = s * sizeof(value_type)
 The number of objects to fit into one memory chunk allocated.
 

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.

The documentation for this class was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 20, 23:31, 2024)