Dune Core Modules (unstable)

A memory pool of objects. More...

#include <dune/common/poolallocator.hh>

Public Types

typedef T MemberType
 The type of object we allocate memory for.
 

Public Member Functions

 Pool ()
 Constructor.
 
 ~Pool ()
 Destructor.
 
void * allocate ()
 Get a new or recycled object. More...
 
void free (void *o)
 Free an object. More...
 
void print (std::ostream &os)
 Print elements in pool for debugging.
 

Static Public Attributes

constexpr static int unionSize
 The size of a union of Reference and MemberType.
 
constexpr static int size
 Size requirement. At least one object has to stored.
 
constexpr static int alignment = std::lcm(alignof(MemberType), alignof(Reference))
 The alignment that suits both the MemberType and the Reference (i.e. their least common multiple).
 
constexpr static int alignedSize
 The aligned size of the type. More...
 
constexpr static int chunkSize
 The size of each chunk memory chunk. More...
 
constexpr static int elements = (chunkSize / alignedSize)
 The number of element each chunk can hold.
 

Detailed Description

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

A memory pool of objects.

The memory for the objects is organized in chunks. Each chunks is capable of holding a specified number of objects. The allocated objects will be properly aligned for fast access. Deallocated objects are cached for reuse to prevent memory fragmentation.

Warning
If the size of the objects allocated is less than the size of a pointer memory is wasted.
Due to aligned issues at the number of bytes of the alignment prerequisite (< 4 bytes) are wasted. This effect becomes negligible for big sizes of chunkSize.
Template Parameters
TThe type that is allocated by us.
sThe size of a memory chunk in bytes.

Member Data Documentation

◆ alignedSize

template<class T , std::size_t s>
constexpr static int Dune::Pool< T, s >::alignedSize
staticconstexpr
Initial value:
= (unionSize % alignment == 0) ?
constexpr static int unionSize
The size of a union of Reference and MemberType.
Definition: poolallocator.hh:113
constexpr static int alignment
The alignment that suits both the MemberType and the Reference (i.e. their least common multiple).
Definition: poolallocator.hh:127

The aligned size of the type.

This size is bigger than sizeof of the type and a multiple of the alignment requirement.

Referenced by Dune::Pool< T, s >::Pool().

◆ chunkSize

template<class T , std::size_t s>
constexpr static int Dune::Pool< T, s >::chunkSize
staticconstexpr
Initial value:
= (size % alignment == 0) ?
constexpr static int size
Size requirement. At least one object has to stored.
Definition: poolallocator.hh:120

The size of each chunk memory chunk.

Will be adapted to be a multiple of the alignment

Referenced by Dune::Pool< T, s >::Pool().


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.80.0 (Apr 18, 22:30, 2024)