Sleipnir C++ API
Loading...
Searching...
No Matches
slp::PoolResource Class Reference

#include <sleipnir/util/pool.hpp>

Public Member Functions

 PoolResource (size_t blocks_per_chunk)
 
 PoolResource (const PoolResource &)=delete
 
PoolResourceoperator= (const PoolResource &)=delete
 
 PoolResource (PoolResource &&)=default
 
PoolResourceoperator= (PoolResource &&)=default
 
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
 

Detailed Description

This class implements a pool memory resource.

The pool allocates chunks of memory and splits them into blocks managed by a free list. Allocations return pointers from the free list, and deallocations return pointers to the free list.

Constructor & Destructor Documentation

◆ PoolResource() [1/3]

slp::PoolResource::PoolResource ( size_t  blocks_per_chunk)
inlineexplicit

Constructs a default PoolResource.

Parameters
blocks_per_chunkNumber of blocks per chunk of memory.

◆ PoolResource() [2/3]

slp::PoolResource::PoolResource ( const PoolResource )
delete

Copy constructor.

◆ PoolResource() [3/3]

slp::PoolResource::PoolResource ( PoolResource &&  )
default

Move constructor.

Member Function Documentation

◆ allocate()

void * slp::PoolResource::allocate ( size_t  bytes,
size_t  alignment = alignof(std::max_align_t) 
)
inline

Returns a block of memory from the pool.

Parameters
bytesNumber of bytes in the block.
alignmentAlignment of the block (unused).
Returns
A block of memory from the pool.

◆ blocks_in_use()

size_t slp::PoolResource::blocks_in_use ( ) const
inlinenoexcept

Returns the number of blocks from this pool resource that are in use.

Returns
The number of blocks from this pool resource that are in use.

◆ deallocate()

void slp::PoolResource::deallocate ( void *  p,
size_t  bytes,
size_t  alignment = alignof(std::max_align_t) 
)
inline

Gives a block of memory back to the pool.

Parameters
pA pointer to the block of memory.
bytesNumber of bytes in the block (unused).
alignmentAlignment of the block (unused).

◆ is_equal()

bool slp::PoolResource::is_equal ( const PoolResource other) const
inlinenoexcept

Returns true if this pool resource has the same backing storage as another.

Parameters
otherThe other pool resource.
Returns
True if this pool resource has the same backing storage as another.

◆ operator=() [1/2]

PoolResource & slp::PoolResource::operator= ( const PoolResource )
delete

Copy assignment operator.

Returns
This pool resource.

◆ operator=() [2/2]

PoolResource & slp::PoolResource::operator= ( PoolResource &&  )
default

Move assignment operator.

Returns
This pool resource.

The documentation for this class was generated from the following file: