Belle II Software light-2406-ragdoll
|
Class to provide a constant access time memory pool for one kind of objects. More...
#include <MemoryPool.h>
Public Member Functions | |
MemoryPool (int n=0) | |
Constructor. | |
~MemoryPool () | |
Free allocated memory. | |
size_t | size () const |
Return number of elements currently stored. | |
T * | operator[] (size_t i) |
Return pointer to memory segment for element i, no range check. | |
T * | at (size_t i) |
Return pointer to memory segment for element i, including range check. | |
void | clear () |
Clear number of entries, does not free memory or call destructors. | |
T * | add () |
Returns an pointer to the next free memory segment, allocating additional memory if necessary. | |
void | reserve (size_t n) |
Make sure there is enough memory allocated for n elements. | |
void | release_memory () |
Release all allocated memory, called automatically upon destruction. | |
Protected Attributes | |
size_t | m_entries |
Number of occupied entries. | |
std::vector< T * > | m_chunks |
Pointers to all allocated memory chunks. | |
Class to provide a constant access time memory pool for one kind of objects.
It is similar to TClonesArray but uses Templates and is also suited for non TObject classes. The Memory will be allocated in chunks, each large enough to hold chunkSize objects of type T.
This class will not initialize the memory, it is the responsibility of the user to call new(pool.add()) T(...) when adding an element to initialize the memory. This is required to make the Pool usable for classes without default constructor
Definition at line 33 of file MemoryPool.h.
|
inlineexplicit |
Constructor.
n | Reserve space for n elements on construction |
Definition at line 40 of file MemoryPool.h.
|
inline |
Free allocated memory.
Definition at line 43 of file MemoryPool.h.
|
inline |
Returns an pointer to the next free memory segment, allocating additional memory if necessary.
Definition at line 74 of file MemoryPool.h.
|
inline |
Return pointer to memory segment for element i, including range check.
i | The index of the memory segment. |
Definition at line 63 of file MemoryPool.h.
|
inline |
Clear number of entries, does not free memory or call destructors.
Definition at line 68 of file MemoryPool.h.
|
inline |
Return pointer to memory segment for element i, no range check.
i | The index of the memory segment. |
Definition at line 56 of file MemoryPool.h.
|
inline |
Release all allocated memory, called automatically upon destruction.
Definition at line 98 of file MemoryPool.h.
|
inline |
Make sure there is enough memory allocated for n elements.
n | The number of elements for which memory should be made available. |
Definition at line 86 of file MemoryPool.h.
|
inline |
Return number of elements currently stored.
Definition at line 49 of file MemoryPool.h.
|
protected |
Pointers to all allocated memory chunks.
Definition at line 109 of file MemoryPool.h.
|
protected |
Number of occupied entries.
Definition at line 108 of file MemoryPool.h.