48 throw std::invalid_argument(
"SlabPool: numSlots must be non-zero");
50 throw std::invalid_argument(
"SlabPool: slotSize must be non-zero");
54 throw std::bad_alloc();
78 slab_(std::move(other.slab_))
80 std::lock_guard<std::mutex> lock(other.mutex_);
94 std::lock_guard<std::mutex> lock(
mutex_);
95 std::lock_guard<std::mutex> otherLock(other.mutex_);
99 slab_ = std::move(other.slab_);
120 std::lock_guard<std::mutex> lock(
mutex_);
122 throw std::runtime_error(
"SlabPool: No free buffers available");
137 std::lock_guard<std::mutex> lock(
mutex_);
139 auto slabBase =
reinterpret_cast<std::uintptr_t
>(
slab_.get());
140 auto bufferAddr =
reinterpret_cast<std::uintptr_t
>(buffer);
141 std::uintptr_t offset = bufferAddr - slabBase;
157 std::lock_guard<std::mutex> lock(
mutex_);
size_t slabSize() const
Returns the total size of the slab in bytes.
Definition SlabPool.h:183
uint8_t * allocate()
Allocates a buffer from the pool.
Definition SlabPool.h:118
std::mutex mutex_
Definition SlabPool.h:193
SlabPool(SlabPool &&other) noexcept
Move constructor for transferring ownership.
Definition SlabPool.h:76
std::unique_ptr< uint8_t[]> slab_
Definition SlabPool.h:192
SlabPool & operator=(SlabPool &&other) noexcept
Move assignment operator for transferring ownership.
Definition SlabPool.h:90
SlabPool & operator=(const SlabPool &)=delete
Deleted assignment operator to prevent copying.
size_t totalSlots() const
Returns the total number of slots in the pool.
Definition SlabPool.h:165
size_t freeCount() const
Returns the number of free buffers currently available.
Definition SlabPool.h:155
void recycle(uint8_t *buffer)
Returns a buffer to the pool for reuse.
Definition SlabPool.h:132
std::queue< uint8_t * > freeBuffers_
Definition SlabPool.h:194
size_t slotSize_
Definition SlabPool.h:190
SlabPool(size_t numSlots, size_t slotSize)
Constructs a slab pool with a specified number of slots and slot size.
Definition SlabPool.h:44
size_t slotSize() const
Returns the size of each slot in bytes.
Definition SlabPool.h:174
~SlabPool()=default
Destructor, frees the slab memory.
size_t numSlots_
Definition SlabPool.h:189
SlabPool(const SlabPool &)=delete
Deleted copy constructor to prevent copying.
size_t slabSize_
Definition SlabPool.h:191
ResWindow.
Definition CompressedChunkCache.h:36