MIRA
|
Provides a pool allocator that is compatible to STL allocators. More...
#include <utils/PoolAllocator.h>
Public Types | |
typedef T | value_type |
Element type. More... | |
typedef std::size_t | size_type |
Quantities of elements. More... | |
typedef std::ptrdiff_t | difference_type |
Difference between two pointers. More... | |
typedef T * | pointer |
Pointer to element. More... | |
typedef T & | reference |
Reference to element. More... | |
typedef const T * | const_pointer |
Reference to element. More... | |
typedef const T & | const_reference |
Constant reference to element. More... | |
Public Member Functions | |
PoolAllocator (size_type poolCapacity=32, bool growPools=true, size_type itemSize=sizeof(T)) | |
Creates a new PoolAllocator. More... | |
~PoolAllocator () | |
Destructor. More... | |
PoolAllocator (PoolAllocator &&other) noexcept | |
PoolAllocator & | operator= (PoolAllocator &&other) noexcept |
void | swap (PoolAllocator &other) |
size_type | allocatedMemory () const |
size_type | usedMemory () const |
size_type | unusedMemory () const |
pointer | address (reference x) const |
Returns the address of x. More... | |
const_pointer | address (const_reference x) const |
Returns the address of x. More... | |
size_type | max_size () const MIRA_NOEXCEPT_OR_NOTHROW |
Returns the maximum number of elements of type T (the template parameter) that could be allocated by a call to member allocate. More... | |
size_type | itemSize () const MIRA_NOEXCEPT_OR_NOTHROW |
Returns the size of each item in bytes. More... | |
pointer | allocate (size_type n, const void *hint=0) |
Allocate a block of storage and returns the pointer, note that the object is not constructed. More... | |
void | construct (pointer p, const_reference val) |
Constructs an object of type T on the location p using its copy constructor to initialize its value to val. More... | |
void | destroy (T *p) |
Destroy an object. Notice that this does not deallocate space for the element. More... | |
void | deallocate (pointer p, size_type n) |
Releases a block of storage previously allocated with member allocate and not yet released. More... | |
T * | construct () |
Allocates and constructs a new object and returns its pointer. More... | |
T * | construct (const_reference val) |
Allocates a new feature and returns its pointer This method is provided for convenience. More... | |
void | destruct (pointer p) |
Destroys the object and deallocates the memory. More... | |
Provides a pool allocator that is compatible to STL allocators.
This allocator is suitable whenever MANY smaller objects are allocated (e.g. several million objects with a size of 32 bytes).
This allocator always allocates pools of objects instead of each object separately. This reduces the management overhead for each object. If the current memory pool is exhausted, another pool is allocated. There are two modes for the allocation of new pools:
This allocator uses the "Simple Segregated Storage" pattern, i.e. it manages a list of deallocated objects (free list) within the allocated memory blocks, i.e. no extra memory is reserved for handling the free list.
typedef T value_type |
Element type.
typedef std::size_t size_type |
Quantities of elements.
typedef std::ptrdiff_t difference_type |
Difference between two pointers.
typedef T* pointer |
Pointer to element.
typedef T& reference |
Reference to element.
typedef const T* const_pointer |
Reference to element.
typedef const T& const_reference |
Constant reference to element.
|
inline |
Creates a new PoolAllocator.
The (initial) size of the pools (in number of objects) is specified as first parameter. The second parameter specifies the mode for the allocation of new pools:
|
inline |
Destructor.
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Returns the address of x.
|
inline |
Returns the maximum number of elements of type T (the template parameter) that could be allocated by a call to member allocate.
|
inline |
Returns the size of each item in bytes.
Allocate a block of storage and returns the pointer, note that the object is not constructed.
|
inline |
Constructs an object of type T on the location p using its copy constructor to initialize its value to val.
|
inline |
Destroy an object. Notice that this does not deallocate space for the element.
Releases a block of storage previously allocated with member allocate and not yet released.
|
inline |
Allocates and constructs a new object and returns its pointer.
This method is provided for convenience but may be up to 10% faster than the STL conform equivalent:
|
inline |
Allocates a new feature and returns its pointer This method is provided for convenience.
It is equivalent to:
|
inline |
Destroys the object and deallocates the memory.
Provided for convenience and as counterpart to the two above construct methods.