bit::memory
Public Types | Public Member Functions | List of all members
bit::memory::pool_allocator Class Reference

This allocator creates a pool of fixed-sized chunk entries for allocations. More...

#include <pool_allocator.hpp>

Public Types

using max_alignment = std::integral_constant< std::size_t, 128 >
 

Public Member Functions

 pool_allocator (std::size_t chunk_size, memory_block block)
 Constructs a pool allocator with chunk sizes of chunk_size, in the arena indicated by block. More...
 
 pool_allocator (pool_allocator &&other) noexcept=default
 Move-constructs the pool_allocator from another allocator. More...
 
 pool_allocator (const pool_allocator &other)=delete
 
pool_allocatoroperator= (pool_allocator &&other)=delete
 
pool_allocatoroperator= (const pool_allocator &other)=delete
 
owner< void * > try_allocate (std::size_t size, std::size_t align, std::size_t offset=0) noexcept
 Tries to allocate size bytes with the alignment of align, offset by offset. More...
 
void deallocate (owner< void *> p, std::size_t size)
 Deallocates memory previously allocated from a call to try_allocate. More...
 
void deallocate_all ()
 Deallocates all memory in this pool_allocator.
 
bool owns (const void *p) const noexcept
 Determines whether the pointer p is owned by this allocator. More...
 
std::size_t max_size () const noexcept
 Determines the max size that this allocator can allocate. More...
 
allocator_info info () const noexcept
 Gets the info about this allocator. More...
 

Detailed Description

This allocator creates a pool of fixed-sized chunk entries for allocations.

Satisfies
ExtendedAllocator

Definition at line 56 of file pool_allocator.hpp.

Member Typedef Documentation

◆ max_alignment

using bit::memory::pool_allocator::max_alignment = std::integral_constant<std::size_t,128>

The max alignment is limited to 128 bytes due to an internal requirement that it stores the offset information

Definition at line 67 of file pool_allocator.hpp.

Constructor & Destructor Documentation

◆ pool_allocator() [1/2]

bit::memory::pool_allocator::pool_allocator ( std::size_t  chunk_size,
memory_block  block 
)

Constructs a pool allocator with chunk sizes of chunk_size, in the arena indicated by block.

Parameters
chunk_sizethe size of each entry in the pool allocator
blockthe block to allocate from

◆ pool_allocator() [2/2]

bit::memory::pool_allocator::pool_allocator ( pool_allocator &&  other)
defaultnoexcept

Move-constructs the pool_allocator from another allocator.

Parameters
otherthe other allocator to move

Member Function Documentation

◆ deallocate()

void bit::memory::pool_allocator::deallocate ( owner< void *>  p,
std::size_t  size 
)

Deallocates memory previously allocated from a call to try_allocate.

Parameters
pthe pointer to the memory to deallocate
sizethe size of the memory previously provided to try_allocate

◆ info()

allocator_info bit::memory::pool_allocator::info ( ) const
noexcept

Gets the info about this allocator.

This defaults to 'pool_allocator'. Use a named_pool_allocator to override this

Returns
the info for this allocator

◆ max_size()

std::size_t bit::memory::pool_allocator::max_size ( ) const
noexcept

Determines the max size that this allocator can allocate.

Returns
the max size

◆ owns()

bool bit::memory::pool_allocator::owns ( const void *  p) const
noexcept

Determines whether the pointer p is owned by this allocator.

Returns
true if the pointer p is originally from this allocator

◆ try_allocate()

owner<void*> bit::memory::pool_allocator::try_allocate ( std::size_t  size,
std::size_t  align,
std::size_t  offset = 0 
)
noexcept

Tries to allocate size bytes with the alignment of align, offset by offset.

Parameters
sizethe requested size of the allocation
alignthe requested alignment of the allocation
offsetthe amount to offset the alignment
Returns
pointer to the allocated memory, or nullptr on failure

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