|
Grok 20.3.2
|
A thread-safe slab-based buffer pool with configurable slot size and number of slots. More...
#include <SlabPool.h>
Public Member Functions | |
| SlabPool (size_t numSlots, size_t slotSize) | |
| Constructs a slab pool with a specified number of slots and slot size. | |
| SlabPool (const SlabPool &)=delete | |
| Deleted copy constructor to prevent copying. | |
| SlabPool & | operator= (const SlabPool &)=delete |
| Deleted assignment operator to prevent copying. | |
| SlabPool (SlabPool &&other) noexcept | |
| Move constructor for transferring ownership. | |
| SlabPool & | operator= (SlabPool &&other) noexcept |
| Move assignment operator for transferring ownership. | |
| ~SlabPool ()=default | |
| Destructor, frees the slab memory. | |
| uint8_t * | allocate () |
| Allocates a buffer from the pool. | |
| void | recycle (uint8_t *buffer) |
| Returns a buffer to the pool for reuse. | |
| size_t | freeCount () const |
| Returns the number of free buffers currently available. | |
| size_t | totalSlots () const |
| Returns the total number of slots in the pool. | |
| size_t | slotSize () const |
| Returns the size of each slot in bytes. | |
| size_t | slabSize () const |
| Returns the total size of the slab in bytes. | |
Private Attributes | |
| size_t | numSlots_ |
| size_t | slotSize_ |
| size_t | slabSize_ |
| std::unique_ptr< uint8_t[]> | slab_ |
| std::mutex | mutex_ |
| std::queue< uint8_t * > | freeBuffers_ |
A thread-safe slab-based buffer pool with configurable slot size and number of slots.
Manages a single contiguous slab of memory, divided into slots of a specified size, with a specified number of slots. Provides allocation and recycling of buffers for tile part fetching and decompression workflows, reducing memory allocation overhead.
|
inline |
Constructs a slab pool with a specified number of slots and slot size.
| numSlots | Number of slots in the slab. |
| slotSize | Size of each slot in bytes. |
| std::invalid_argument | if numSlots or slotSize is 0. |
| std::bad_alloc | if slab allocation fails. |
References freeBuffers_, numSlots_, slab_, slabSize_, slotSize(), and slotSize_.
Referenced by operator=(), operator=(), SlabPool(), and SlabPool().
|
delete |
Deleted copy constructor to prevent copying.
References SlabPool().
|
inlinenoexcept |
Move constructor for transferring ownership.
References freeBuffers_, and SlabPool().
|
default |
Destructor, frees the slab memory.
|
inline |
Allocates a buffer from the pool.
| std::runtime_error | if no free buffers are available. |
References freeBuffers_, and mutex_.
|
inline |
Returns the number of free buffers currently available.
References freeBuffers_, and mutex_.
Deleted assignment operator to prevent copying.
References SlabPool().
Move assignment operator for transferring ownership.
References freeBuffers_, mutex_, numSlots_, slab_, SlabPool(), slabSize_, and slotSize_.
|
inline |
Returns a buffer to the pool for reuse.
| buffer | Pointer to the buffer to recycle (must be from this pool). |
References freeBuffers_, mutex_, slab_, slabSize_, and slotSize_.
|
inline |
Returns the total size of the slab in bytes.
References slabSize_.
|
inline |
Returns the size of each slot in bytes.
References slotSize_.
Referenced by SlabPool().
|
inline |
|
private |
Referenced by allocate(), freeCount(), operator=(), recycle(), SlabPool(), and SlabPool().
|
mutableprivate |
Referenced by allocate(), freeCount(), operator=(), and recycle().
|
private |
Referenced by operator=(), SlabPool(), and totalSlots().
|
private |
Referenced by operator=(), recycle(), and SlabPool().
|
private |
Referenced by operator=(), recycle(), SlabPool(), and slabSize().
|
private |
Referenced by operator=(), recycle(), SlabPool(), and slotSize().