mCRL2
|
The memory pool allocates elements of size T from blocks. More...
#include <memory_pool.h>
Public Member Functions | |
memory_pool ()=default | |
~memory_pool () | |
Triggers the (possibly non-trivial) destructor of all elements stored in the pool. | |
T * | allocate () |
Reuses memory from block and allocates a new block when no slots are free. | |
void | deallocate (T *pointer) |
Free the memory used by the given pointer that has been allocated by this pool. | |
std::size_t | consolidate () |
Frees blocks that are no longer storing elements of T. | |
bool | has_free_slots () const noexcept |
std::size_t | capacity () const noexcept |
memory_pool (memory_pool &&other)=default | |
memory_pool & | operator= (memory_pool &&other)=default |
Private Types | |
using | Freelist = typename detail::free_list< T > |
using | FreelistIt = typename Freelist::iterator |
using | Slot = typename Freelist::slot |
using | Block = std::array< Slot, ElementsPerBlock > |
An array that stores ElementsPerBlock number of objects of type T. | |
using | SizeType = typename std::conditional< ThreadSafe, std::atomic< std::size_t >, std::size_t >::type |
The last slot in the first block that has never been returned by allocate. | |
Private Member Functions | |
bool | contains (T *p) |
Private Member Functions inherited from mcrl2::utilities::noncopyable | |
noncopyable ()=default | |
noncopyable (const noncopyable &)=delete | |
noncopyable & | operator= (const noncopyable &)=delete |
Private Attributes | |
SizeType | m_current_index = ElementsPerBlock |
SizeType | m_number_of_blocks = 0 |
Equal to the size of the blocks array to prevent iterating over the block list. | |
std::forward_list< Block > | m_blocks |
The list of blocks allocated by this pool. | |
mcrl2::utilities::mutex | m_block_mutex = {} |
Ensures that the block list is only modified by a single thread. | |
Freelist | m_freelist |
Indicates the head of the freelist. | |
The memory pool allocates elements of size T from blocks.
When ThreadSafe is true then the thread-safe guarantees will be satisfied.
Definition at line 33 of file memory_pool.h.
|
private |
An array that stores ElementsPerBlock number of objects of type T.
Definition at line 197 of file memory_pool.h.
|
private |
Definition at line 192 of file memory_pool.h.
|
private |
Definition at line 193 of file memory_pool.h.
|
private |
The last slot in the first block that has never been returned by allocate.
Definition at line 200 of file memory_pool.h.
|
private |
Definition at line 194 of file memory_pool.h.
|
default |
|
inline |
Triggers the (possibly non-trivial) destructor of all elements stored in the pool.
For all actual elements stored in the pool trigger the destructor.
Definition at line 40 of file memory_pool.h.
|
default |
|
inline |
Reuses memory from block and allocates a new block when no slots are free.
Definition at line 80 of file memory_pool.h.
|
inlinenoexcept |
Definition at line 182 of file memory_pool.h.
|
inline |
Frees blocks that are no longer storing elements of T.
Definition at line 121 of file memory_pool.h.
|
inlineprivate |
Definition at line 216 of file memory_pool.h.
|
inline |
Free the memory used by the given pointer that has been allocated by this pool.
Definition at line 109 of file memory_pool.h.
|
inlinenoexcept |
Definition at line 175 of file memory_pool.h.
|
default |
|
private |
Ensures that the block list is only modified by a single thread.
Definition at line 210 of file memory_pool.h.
|
private |
The list of blocks allocated by this pool.
Definition at line 207 of file memory_pool.h.
|
private |
Definition at line 201 of file memory_pool.h.
|
private |
Indicates the head of the freelist.
Definition at line 213 of file memory_pool.h.
|
private |
Equal to the size of the blocks array to prevent iterating over the block list.
Definition at line 204 of file memory_pool.h.