Jobrocket
jobrocket::detail::FixedPoolAllocator Class Reference

#include <FixedPoolAllocator.hpp>

Overview

A pool of fixed-size that allocates raw memory in same-sized blocks. All memory managed by the allocator is created at construction and deleted at destruction.

Public Member Functions

 FixedPoolAllocator ()=default
 
 FixedPoolAllocator (const size_t block_size, const uint32_t max_blocks)
 
 FixedPoolAllocator (const FixedPoolAllocator &other)=delete
 
FixedPoolAllocatoroperator= (const FixedPoolAllocator &other)=delete
 
 FixedPoolAllocator (FixedPoolAllocator &&other) noexcept
 
FixedPoolAllocatoroperator= (FixedPoolAllocator &&other) noexcept
 
 ~FixedPoolAllocator ()
 
void * allocate ()
 Allocates a new block of memory from the pool and returns a pointer to it. More...
 
bool free (void *data)
 
void reset ()
 Resets the pool and zeroes out all memory. More...
 
uint32_t block_capacity ()
 Gets the maximum number of blocks the pool can allocate. More...
 
uint32_t blocks_initialized ()
 Gets the current number of blocks allocated. More...
 

Constructor & Destructor Documentation

◆ FixedPoolAllocator() [1/4]

jobrocket::detail::FixedPoolAllocator::FixedPoolAllocator ( )
default

◆ FixedPoolAllocator() [2/4]

jobrocket::detail::FixedPoolAllocator::FixedPoolAllocator ( const size_t  block_size,
const uint32_t  max_blocks 
)
inline

Initializes the allocator with block_size bytes allocated per memory block and max_blocks number of blocks capacity

◆ FixedPoolAllocator() [3/4]

jobrocket::detail::FixedPoolAllocator::FixedPoolAllocator ( const FixedPoolAllocator other)
delete

◆ FixedPoolAllocator() [4/4]

jobrocket::detail::FixedPoolAllocator::FixedPoolAllocator ( FixedPoolAllocator &&  other)
inlinenoexcept

◆ ~FixedPoolAllocator()

jobrocket::detail::FixedPoolAllocator::~FixedPoolAllocator ( )
inline

Member Function Documentation

◆ allocate()

void* jobrocket::detail::FixedPoolAllocator::allocate ( )
inline

Allocates a new block of memory from the pool and returns a pointer to it.

◆ block_capacity()

uint32_t jobrocket::detail::FixedPoolAllocator::block_capacity ( )
inline

Gets the maximum number of blocks the pool can allocate.

◆ blocks_initialized()

uint32_t jobrocket::detail::FixedPoolAllocator::blocks_initialized ( )
inline

Gets the current number of blocks allocated.

◆ free()

bool jobrocket::detail::FixedPoolAllocator::free ( void *  data)
inline

Frees memory allocated by allocate(). If the data wasn't allocated by the internal pool, this function causes undefined behaviour and will log an error

◆ operator=() [1/2]

FixedPoolAllocator& jobrocket::detail::FixedPoolAllocator::operator= ( const FixedPoolAllocator other)
delete

◆ operator=() [2/2]

FixedPoolAllocator& jobrocket::detail::FixedPoolAllocator::operator= ( FixedPoolAllocator &&  other)
inlinenoexcept

◆ reset()

void jobrocket::detail::FixedPoolAllocator::reset ( )
inline

Resets the pool and zeroes out all memory.