#include <Memory.h>
Classes | |
struct | Chunk |
Public Member Functions | |
TailPool (unsigned step) | |
T * | getMem (unsigned count=1) |
Get new memory. | |
void | returnMem (unsigned count) |
Return allocated memory. | |
void | reset () |
Private Attributes | |
vector< Chunk > | chunks |
The array of all allocated chunks. | |
unsigned | step |
The size(in elements) of each allocation. | |
Chunk * | chunk |
Pointer to the current chunk. | |
unsigned | chunkIndex |
The index of current chunk in the chunk array. |
A simple pool that requires the memory to be returned in same order as it was requested. No checking of this condition is done by the pool.
The pool allocates memory in chunks. New chunk is allocated if the currently used cannot satisfy the request. The unused memory in current chunk is than waster. The maximum possible request is passed as constructor parameter.
When memory is returned, no memory is dealocated. Insted it is marked as free and ready for next requests. The allocated memory is freed only during the object destruction.
T * TailPool< T >::getMem | ( | unsigned | count = 1 |
) | [inline] |
Get new memory.
Returns pointer to linear array of elements with requested size. The requested count must not be larger than the value passed to constructor.
count | Size of requested memory in element count |
void TailPool< T >::returnMem | ( | unsigned | count | ) | [inline] |
Return allocated memory.
Return the previously requested memory. Must be in returned in same order as requested!!!. No memory is actualy deallocated.
count | Size of returned memory in element count. |