Object pool for zero-allocation management of frequently created/destroyed objects.
More...
#include <memory_pool.hpp>
|
| | ObjectPool (std::size_t initial_capacity=1024) |
| | Constructor - pre-allocates initial capacity.
|
| |
| | ~ObjectPool () noexcept |
| | Destructor - frees all memory blocks.
|
| |
| | ObjectPool (const ObjectPool &)=delete |
| |
| ObjectPool & | operator= (const ObjectPool &)=delete |
| |
| | ObjectPool (ObjectPool &&other) noexcept |
| |
| ObjectPool & | operator= (ObjectPool &&other) noexcept |
| |
| T * | allocate () |
| | Allocate an object from the pool Returns a pointer to uninitialized memory.
|
| |
| template<typename... Args> |
| T * | construct (Args &&... args) |
| | Construct an object in-place with arguments.
|
| |
| void | deallocate (T *ptr) noexcept |
| | Deallocate an object (does not call destructor)
|
| |
| void | destroy (T *ptr) noexcept |
| | Destroy and deallocate an object.
|
| |
| bool | reserve (std::size_t n) |
| | Reserve capacity for at least n objects.
|
| |
| std::size_t | capacity () const noexcept |
| | Get current capacity (total objects that can be stored)
|
| |
| std::size_t | size () const noexcept |
| | Get current size (objects currently allocated)
|
| |
| std::size_t | available () const noexcept |
| | Get number of available objects in free list.
|
| |
| bool | empty () const noexcept |
| | Check if pool is empty.
|
| |
| void | clear () noexcept |
| | Clear all allocated objects (calls destructors if any are alive) Warning: This assumes all objects have been properly destroyed.
|
| |
template<typename T>
class slick::orderbook::detail::ObjectPool< T >
Object pool for zero-allocation management of frequently created/destroyed objects.
Benefits:
- Zero allocations in hot path (after initial pool creation)
- Cache-friendly memory layout (objects allocated in contiguous blocks)
- Fast allocation/deallocation (free-list based, O(1))
- Automatic memory management with RAII
Usage:
Order* order = pool.allocate();
pool.deallocate(order);
Object pool for zero-allocation management of frequently created/destroyed objects.
Order structure for Level 3 orderbook Uses intrusive list design for zero-allocation order queues at ...
- Template Parameters
-
Definition at line 34 of file memory_pool.hpp.
◆ ObjectPool() [1/3]
Constructor - pre-allocates initial capacity.
- Parameters
-
| initial_capacity | Number of objects to pre-allocate |
Definition at line 43 of file memory_pool.hpp.
◆ ~ObjectPool()
◆ ObjectPool() [2/3]
◆ ObjectPool() [3/3]
◆ allocate()
Allocate an object from the pool Returns a pointer to uninitialized memory.
- Returns
- Pointer to allocated memory, or nullptr if allocation fails
Definition at line 93 of file memory_pool.hpp.
◆ available()
Get number of available objects in free list.
Definition at line 181 of file memory_pool.hpp.
◆ capacity()
Get current capacity (total objects that can be stored)
Definition at line 171 of file memory_pool.hpp.
◆ clear()
Clear all allocated objects (calls destructors if any are alive) Warning: This assumes all objects have been properly destroyed.
Definition at line 192 of file memory_pool.hpp.
◆ construct()
template<typename T >
template<typename... Args>
Construct an object in-place with arguments.
- Parameters
-
| args | Constructor arguments |
- Returns
- Pointer to constructed object, or nullptr if allocation fails
Definition at line 122 of file memory_pool.hpp.
◆ deallocate()
Deallocate an object (does not call destructor)
- Parameters
-
| ptr | Pointer to object to deallocate |
Definition at line 137 of file memory_pool.hpp.
◆ destroy()
Destroy and deallocate an object.
- Parameters
-
| ptr | Pointer to object to destroy |
Definition at line 151 of file memory_pool.hpp.
◆ empty()
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ reserve()
Reserve capacity for at least n objects.
- Parameters
-
| n | Minimum capacity to reserve |
- Returns
- true if successful, false otherwise
Definition at line 161 of file memory_pool.hpp.
◆ size()
Get current size (objects currently allocated)
Definition at line 176 of file memory_pool.hpp.
The documentation for this class was generated from the following file: