Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::object_pool< T, UserAllocator > Singleton Reference

A template class that can be used for fast and efficient memory allocation of objects. More...

#include <poolfwd.hpp>

Inheritance diagram for boost::object_pool< T, UserAllocator >:
Collaboration diagram for boost::object_pool< T, UserAllocator >:

Public Types

typedef T element_type
 ElementType. More...
 
typedef UserAllocator user_allocator
 
typedef pool< UserAllocator >
::size_type 
size_type
 pool<UserAllocator>::size_type More...
 
typedef pool< UserAllocator >
::difference_type 
difference_type
 pool<UserAllocator>::difference_type More...
 

Public Member Functions

 object_pool (const size_type arg_next_size=32, const size_type arg_max_size=0)
 
 ~object_pool ()
 
element_type *malloc BOOST_PREVENT_MACRO_SUBSTITUTION ()
 
void free BOOST_PREVENT_MACRO_SUBSTITUTION (element_type *const chunk)
 
bool is_from (element_type *const chunk) const
 
element_typeconstruct ()
 
void destroy (element_type *const chunk)
 
size_type get_next_size () const
 
void set_next_size (const size_type x)
 

Protected Member Functions

pool< UserAllocator > & store ()
 
const pool< UserAllocator > & store () const
 

Static Protected Member Functions

static void *& nextof (void *const ptr)
 

Detailed Description

template<typename T, typename UserAllocator>
singleton boost::object_pool< T, UserAllocator >

A template class that can be used for fast and efficient memory allocation of objects.

It also provides automatic destruction of non-deallocated objects.

T The type of object to allocate/deallocate. T must have a non-throwing destructor.

UserAllocator Defines the allocator that the underlying Pool will use to allocate memory from the system. See User Allocators for details.

Class object_pool is a template class that can be used for fast and efficient memory allocation of objects. It also provides automatic destruction of non-deallocated objects.

When the object pool is destroyed, then the destructor for type T is called for each allocated T that has not yet been deallocated. O(N).

Whenever an object of type ObjectPool needs memory from the system, it will request it from its UserAllocator template parameter. The amount requested is determined using a doubling algorithm; that is, each time more system memory is allocated, the amount of system memory requested is doubled. Users may control the doubling algorithm by the parameters passed to the object_pool's constructor.

Member Typedef Documentation

template<typename T, typename UserAllocator >
typedef pool<UserAllocator>::difference_type boost::object_pool< T, UserAllocator >::difference_type

pool<UserAllocator>::difference_type

template<typename T, typename UserAllocator >
typedef T boost::object_pool< T, UserAllocator >::element_type

ElementType.

template<typename T, typename UserAllocator >
typedef pool<UserAllocator>::size_type boost::object_pool< T, UserAllocator >::size_type

pool<UserAllocator>::size_type

template<typename T, typename UserAllocator >
typedef UserAllocator boost::object_pool< T, UserAllocator >::user_allocator

Constructor & Destructor Documentation

template<typename T, typename UserAllocator >
boost::object_pool< T, UserAllocator >::object_pool ( const size_type  arg_next_size = 32,
const size_type  arg_max_size = 0 
)
inlineexplicit

Constructs a new (empty by default) ObjectPool.

Parameters
next_sizeNumber of chunks to request from the system the next time that object needs to allocate system memory (default 32).
Precondition
next_size != 0.
Parameters
max_sizeMaximum number of chunks to ever request from the system - this puts a cap on the doubling algorithm used by the underlying pool.
template<typename T , typename UserAllocator >
boost::object_pool< T, UserAllocator >::~object_pool ( )

Member Function Documentation

template<typename T, typename UserAllocator >
element_type* malloc boost::object_pool< T, UserAllocator >::BOOST_PREVENT_MACRO_SUBSTITUTION ( )
inline

Allocates memory that can hold one object of type ElementType.

If out of memory, returns 0.

Amortized O(1).

template<typename T, typename UserAllocator >
void free boost::object_pool< T, UserAllocator >::BOOST_PREVENT_MACRO_SUBSTITUTION ( element_type *const  chunk)
inline

De-Allocates memory that holds a chunk of type ElementType.

Note that p may not be 0.
Note that the destructor for p is not called. O(N).

template<typename T, typename UserAllocator >
element_type* boost::object_pool< T, UserAllocator >::construct ( )
inline
Returns
A pointer to an object of type T, allocated in memory from the underlying pool and default constructed. The returned objected can be freed by a call to destroy. Otherwise the returned object will be automatically destroyed when *this is destroyed.
template<typename T, typename UserAllocator >
void boost::object_pool< T, UserAllocator >::destroy ( element_type *const  chunk)
inline

Destroys an object allocated with construct.

Equivalent to:

p->~ElementType(); this->free(p);

Precondition
p must have been previously allocated from *this via a call to construct.
template<typename T, typename UserAllocator >
size_type boost::object_pool< T, UserAllocator >::get_next_size ( ) const
inline
Returns
The number of chunks that will be allocated next time we run out of memory.
template<typename T, typename UserAllocator >
bool boost::object_pool< T, UserAllocator >::is_from ( element_type *const  chunk) const
inline
Returns
true if chunk was allocated from *this or may be returned as the result of a future allocation from *this.

Returns false if chunk was allocated from some other pool or may be returned as the result of a future allocation from some other pool.

Otherwise, the return value is meaningless.

Note
This function may NOT be used to reliably test random pointer values!
template<typename T, typename UserAllocator >
static void* & boost::object_pool< T, UserAllocator >::nextof ( void *const  ptr)
inlinestaticprotected
Returns
The next memory block after ptr (for the sake of code readability :)
template<typename T, typename UserAllocator >
void boost::object_pool< T, UserAllocator >::set_next_size ( const size_type  x)
inline

Set a new number of chunks to allocate the next time we run out of memory.

Parameters
xwanted next_size (must not be zero).
template<typename T, typename UserAllocator >
pool<UserAllocator>& boost::object_pool< T, UserAllocator >::store ( )
inlineprotected
template<typename T, typename UserAllocator >
const pool<UserAllocator>& boost::object_pool< T, UserAllocator >::store ( ) const
inlineprotected
Returns
The underlying boost:: pool storage used by *this.

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