Loading...
Searching...
No Matches
Dune::Pool< T, s > Class Template Reference
Common » Allocators

A memory pool of objects. More...

`#include <dune/common/poolallocator.hh>`

Inheritance diagram for Dune::Pool< T, s >:

## 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.
void | free (void *o)
| Free an object.
void | print (std::ostream &os)
| Print elements in pool for debugging.

## Static Public Attributes

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

## Friends

struct | ::testPoolMain< s, T >
template<class, std::size_t>
class | PoolAllocator

## 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

  T | The type that is allocated by us.
  s | The size of a memory chunk in bytes.

## Member Typedef Documentation

## MemberType

template<class T, std::size_t s>

typedef T Dune::Pool< T, s >::MemberType

The type of object we allocate memory for.

## Friends And Related Symbol Documentation

## ::testPoolMain< s, T >

template<class T, std::size_t s>

friend struct ::testPoolMain< s, T >

friend

## PoolAllocator

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

friend class PoolAllocator

friend

## Member Data Documentation

## alignedSize

template<class T, std::size_t s>

int Dune::Pool< T, s >::alignedSize

static constexpr

Initial value:
= (unionSize % alignment == 0) ?
unionSize :
((unionSize / alignment + 1) * alignment)
Dune::Pool::alignment
static constexpr int alignment
The alignment that suits both the MemberType and the Reference (i.e. their least common multiple).
Definition poolallocator.hh:127
Dune::Pool::unionSize
static constexpr int unionSize
The size of a union of Reference and MemberType.
Definition poolallocator.hh:113

The aligned size of the type.

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

## alignment

template<class T, std::size_t s>

int Dune::Pool< T, s >::alignment = std::lcm(alignof(MemberType), alignof(Reference))

static constexpr

The alignment that suits both the MemberType and the Reference (i.e. their least common multiple).

## chunkSize

template<class T, std::size_t s>

int Dune::Pool< T, s >::chunkSize

static constexpr

Initial value:
= (size % alignment == 0) ?
size : ((size / alignment + 1)* alignment)
Dune::Pool::size
static constexpr 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

## elements

template<class T, std::size_t s>

int Dune::Pool< T, s >::elements = (chunkSize / alignedSize)

static constexpr

The number of element each chunk can hold.

## size

template<class T, std::size_t s>

int Dune::Pool< T, s >::size

static constexpr

Initial value:
= (sizeof(MemberType) <= s && sizeof(Reference) <= s) ?
s : unionSize
Dune::Pool::MemberType
T MemberType
The type of object we allocate memory for.
Definition poolallocator.hh:108

Size requirement. At least one object has to stored.

## unionSize

template<class T, std::size_t s>

int Dune::Pool< T, s >::unionSize

static constexpr

Initial value:
= (sizeof(MemberType) < sizeof(Reference)) ?
sizeof(Reference) : sizeof(MemberType)

The size of a union of Reference and MemberType.

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

- poolallocator.hh