Support class for type_pool. More...
#include <type_pool.h>
Public Types | |
typedef Allocator | allocator_type |
Exposes type of Allocator. | |
typedef allocator_type::pointer | pointer |
Exposes type of Allocator::pointer. | |
Public Member Functions | |
chunk_pool (size_t preallocate=0, size_t cap=max_size()) | |
Constructor. | |
virtual | ~chunk_pool () |
Destructor. | |
pointer | allocate () |
Allocates or recycles an array. | |
void | release (typename Allocator::pointer p) |
Returns a previously allocated chunk to the pool. | |
Static Protected Member Functions | |
static size_t | max_size () |
The store's maximum size. |
Support class for type_pool.
This class implements the a free store for arrays of unsigned char. type_pool specifies sizeof(T)
as the size of arrays.
S | The size of the memory chunks to alllocate and pool. |
Allocator | The allocation policy class to use when allocating and deallocating memory. |
chunk_pool< S, Allocator >::chunk_pool | ( | size_t | preallocate = 0 , |
size_t | cap = max_size() |
||
) | [inline] |
Constructor.
Performs preallocation, if requested, on a separate thread. The first allocation requested will wait until preallocation is over.
preallocate | The number of arrays for which to preallocate memory. |
cap | The maximum number of arrays to keep in the store. |
virtual chunk_pool< S, Allocator >::~chunk_pool | ( | ) | [inline, virtual] |
Destructor.
Deallocates all arrays in the free store.
pointer chunk_pool< S, Allocator >::allocate | ( | ) | [inline] |
Allocates or recycles an array.
If the free store is empty, it allocates a new array using Allocator::allocate()
. If the free store is not empty, recycles an array from it.
void chunk_pool< S, Allocator >::release | ( | typename Allocator::pointer | p | ) | [inline] |
Returns a previously allocated chunk to the pool.
If the pool is already at maximum capacity, the chunk is not stored.
p | Pointer to previously allocated chunk. |