dune-common  2.4.1
Classes | Public Types | Public Member Functions | List of all members
Dune::Pool< T, s > Class Template Reference

A memory pool of objects. More...

#include <dune/common/poolallocator.hh>

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

Public Types

enum  {
  unionSize, size, alignment = Lcm<AlignmentOf<MemberType>::value,AlignmentOf<Reference>::value>::value, alignedSize,
  chunkSize, elements = ((chunkSize - alignment + 1)/ alignedSize)
}
 
typedef T MemberType
 The type of object we allocate memory for. More...
 

Public Member Functions

 Pool ()
 Constructor. More...
 
 ~Pool ()
 Destructor. More...
 
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. More...
 

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 Typedef Documentation

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

The type of object we allocate memory for.


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