A template class that can be used for fast and efficient memory allocation of objects. More...
#include <poolfwd.hpp>
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_type * | construct () |
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) |
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.
typedef pool<UserAllocator>::difference_type boost::object_pool< T, UserAllocator >::difference_type |
pool<UserAllocator>::difference_type
typedef T boost::object_pool< T, UserAllocator >::element_type |
ElementType.
typedef pool<UserAllocator>::size_type boost::object_pool< T, UserAllocator >::size_type |
pool<UserAllocator>::size_type
typedef UserAllocator boost::object_pool< T, UserAllocator >::user_allocator |
|
inlineexplicit |
Constructs a new (empty by default) ObjectPool.
next_size | Number of chunks to request from the system the next time that object needs to allocate system memory (default 32). |
max_size | Maximum number of chunks to ever request from the system - this puts a cap on the doubling algorithm used by the underlying pool. |
boost::object_pool< T, UserAllocator >::~object_pool | ( | ) |
References boost::xpressive::first, boost::multiprecision::backends::i, boost::next(), and T.
|
inline |
Allocates memory that can hold one object of type ElementType.
If out of memory, returns 0.
Amortized O(1).
|
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).
|
inline |
|
inline |
|
inline |
|
inline |
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.
|
inlinestaticprotected |
|
inline |
Set a new number of chunks to allocate the next time we run out of memory.
x | wanted next_size (must not be zero). |
|
inlineprotected |
Referenced by boost::object_pool< T >::BOOST_PREVENT_MACRO_SUBSTITUTION(), boost::object_pool< T >::get_next_size(), boost::object_pool< T >::is_from(), and boost::object_pool< T >::set_next_size().
|
inlineprotected |