A memory pool of objects.
More...
#include <dune/common/poolallocator.hh>
List of all members.
Classes |
struct | Chunk |
| Chunk of memory managed by the pool.
|
struct | Reference |
| Reference to next free element.
|
Public Types |
enum | {
unionSize,
size,
alignment = Lcm<AlignmentOf<MemberType>::value,
value,
alignedSize,
chunkSize,
elements = ((chunkSize - alignment + 1)/ alignedSize)
} |
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.
|
Friends |
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 negligable 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
template<class T , std::size_t s>
The type of object we allocate memory for.
Member Enumeration Documentation
template<class T , std::size_t s>
- Enumerator:
unionSize |
The size of a union of Reference and MemberType.
|
size |
Size requirement. At least one object has to stored.
|
alignment |
The alignment that suits both the MemberType and the Reference (i.e. their least common multiple).
|
value |
|
alignedSize |
The aligned size of the type.
This size is bigger than sizeof of the type and a multiple of the alignment requirement.
|
chunkSize |
The size of each chunk memory chunk.
Will be adapted to be a multiple of the alignment plus an offset to handle the case that the pointer to the memory does not satisfy the alignment requirements.
|
elements |
The number of element each chunk can hold.
|
Friends And Related Function Documentation
template<class T , std::size_t s>
The documentation for this class was generated from the following file: