type_pool  1.2
All Classes Files Functions Typedefs
Public Types | Public Member Functions | Static Protected Member Functions
chunk_pool< S, Allocator > Class Template Reference

Support class for type_pool. More...

#include <type_pool.h>

Inheritance diagram for chunk_pool< S, Allocator >:
Inheritance graph
[legend]

List of all members.

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.

Detailed Description

template<size_t S, class Allocator = std::allocator<unsigned char[S]>>
class chunk_pool< S, Allocator >

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.

Parameters:
SThe size of the memory chunks to alllocate and pool.
AllocatorThe allocation policy class to use when allocating and deallocating memory.

Constructor & Destructor Documentation

template<size_t S, class Allocator = std::allocator<unsigned char[S]>>
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.

Parameters:
preallocateThe number of arrays for which to preallocate memory.
capThe maximum number of arrays to keep in the store.
template<size_t S, class Allocator = std::allocator<unsigned char[S]>>
virtual chunk_pool< S, Allocator >::~chunk_pool ( ) [inline, virtual]

Destructor.

Deallocates all arrays in the free store.


Member Function Documentation

template<size_t S, class Allocator = std::allocator<unsigned char[S]>>
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.

template<size_t S, class Allocator = std::allocator<unsigned char[S]>>
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.

Parameters:
pPointer to previously allocated chunk.

The documentation for this class was generated from the following file: