![]() |
Sleipnir C++ API
|
#include </home/runner/work/Sleipnir/Sleipnir/include/sleipnir/util/pool.hpp>
Public Member Functions | |
| PoolResource (size_t blocks_per_chunk) | |
| ~PoolResource () | |
| Destructor. | |
| PoolResource (const PoolResource &)=delete | |
| Copy constructor. | |
| PoolResource & | operator= (const PoolResource &)=delete |
| PoolResource (PoolResource &&) | |
| Move constructor. | |
| PoolResource & | operator= (PoolResource &&) |
| void * | allocate (size_t bytes, size_t alignment=alignof(std::max_align_t)) |
| void | deallocate (void *p, size_t bytes, size_t alignment=alignof(std::max_align_t)) |
| bool | is_equal (const PoolResource &other) const noexcept |
| size_t | blocks_in_use () const noexcept |
This class implements a pool memory resource.
The pool allocates chunks of memory and splits them into blocks managed by free lists. Each distinct requested block size gets its own chunks and free list. Allocations return pointers from the free list for the requested size, and deallocations return pointers to the free list of the chunk they came from.
|
explicit |
Constructs a default PoolResource.
| blocks_per_chunk | Number of blocks per chunk of memory. |
| void * slp::PoolResource::allocate | ( | size_t | bytes, |
| size_t | alignment = alignof(std::max_align_t) |
||
| ) |
Returns a block of memory from the pool.
| bytes | Number of bytes in the block. |
| alignment | Alignment of the block. Must be a power of two no larger than alignof(std::max_align_t). |
|
inlinenoexcept |
Returns the number of blocks from this pool resource that are in use.
| void slp::PoolResource::deallocate | ( | void * | p, |
| size_t | bytes, | ||
| size_t | alignment = alignof(std::max_align_t) |
||
| ) |
Gives a block of memory back to the pool.
The block is returned to the free list of the chunk it was allocated from, so the size and alignment don't need to match the original allocation.
| p | A pointer to the block of memory. |
| bytes | Number of bytes in the block (unused). |
| alignment | Alignment of the block (unused). |
|
inlinenoexcept |
Returns true if this pool resource has the same backing storage as another.
| other | The other pool resource. |
|
delete |
Copy assignment operator.
| PoolResource & slp::PoolResource::operator= | ( | PoolResource && | ) |
Move assignment operator.