![]() |
Belle II Software
release-05-01-25
|
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. More... | |
~MemoryPool () | |
Free allocated memory. | |
size_t | size () const |
Return number of elements currently stored. More... | |
T * | operator[] (size_t i) |
Return pointer to memory segment for element i, no range check. More... | |
T * | at (size_t i) |
Return pointer to memory segment for element i, including range check. More... | |
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. More... | |
void | reserve (size_t n) |
Make sure there is enough memory allocated for n elements. More... | |
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 43 of file MemoryPool.h.
|
inlineexplicit |
Constructor.
n | Reserve space for n elements on construction |
Definition at line 50 of file MemoryPool.h.
|
inline |
Returns an pointer to the next free memory segment, allocating additional memory if necessary.
Definition at line 84 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 73 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 66 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 96 of file MemoryPool.h.
|
inline |
Return number of elements currently stored.
Definition at line 59 of file MemoryPool.h.