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

A cache containing an intrinsically linked list of memory_blocks. More...

#include <memory_block_cache.hpp>

Public Member Functions

 memory_block_cache () noexcept
 Default constructs a block cache.
 
 memory_block_cache (memory_block_cache &&other) noexcept=default
 Move-constructs a memory_block_cache from an existing one. More...
 
 memory_block_cache (const memory_block_cache &other)=delete
 
memory_block_cacheoperator= (memory_block_cache &&other)=delete
 
memory_block_cacheoperator= (const memory_block_cache &other)=delete
 
bool empty () const noexcept
 Returns whether or not this memory_block_cache is empty. More...
 
std::size_t size () const noexcept
 Returns the number of memory_blocks in this cache. More...
 
std::size_t size_bytes () const noexcept
 Returns the size in bytes of all the memory_blocks in the cache. More...
 
bool contains (const void *ptr) const noexcept
 Evaluates whether ptr exists within this memory_block_cache. More...
 
const memory_blockpeek () const noexcept
 Views the front memory block of this cache. More...
 
owner< memory_blockrequest_block () noexcept
 Requests a block from the current block cache. More...
 
template<typename BlockAllocator >
owner< memory_blockrequest_block (BlockAllocator &alloc)
 Requests a block from. More...
 
void steal_block (memory_block_cache &other) noexcept
 Acquires an entry from another cache. More...
 
void store_block (owner< memory_block > block) noexcept
 Stores an allocated block inside this memory_block_cache. More...
 
void swap (memory_block_cache &other) noexcept
 Swaps this with another block cache. More...
 

Detailed Description

A cache containing an intrinsically linked list of memory_blocks.

Blocks in this cache are not guaranteed to all be of the same size. Memory blocks may originate from different allocators, and represent different regions of memory – however this is not the recommended practice.

Every memory_block in the memory_block_cache must be aligned to at least alignof(memory_block) bytes – otherwise it is undefined behavior

Definition at line 60 of file memory_block_cache.hpp.

Constructor & Destructor Documentation

◆ memory_block_cache()

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

Move-constructs a memory_block_cache from an existing one.

Parameters
otherthe other memory_block_cache to move

Member Function Documentation

◆ contains()

bool bit::memory::memory_block_cache::contains ( const void *  ptr) const
noexcept

Evaluates whether ptr exists within this memory_block_cache.

Parameters
ptrthe pointer to evaluate
Returns
true whether ptr

◆ empty()

bool bit::memory::memory_block_cache::empty ( ) const
noexcept

Returns whether or not this memory_block_cache is empty.

Returns
true if this memory_block_cache is empty, false otherwise

◆ peek()

const memory_block& bit::memory::memory_block_cache::peek ( ) const
noexcept

Views the front memory block of this cache.

Precondition
!empty()
Note
It is undefined behaviour to invoke this function if the cache is empty
Returns
the front cache entry

◆ request_block() [1/2]

owner<memory_block> bit::memory::memory_block_cache::request_block ( )
noexcept

Requests a block from the current block cache.

If one can be provided, the block is released from this cache and is now owned by the accessor

Returns
a memory block, if available, or a null block if unable

◆ request_block() [2/2]

template<typename BlockAllocator >
owner<memory_block> bit::memory::memory_block_cache::request_block ( BlockAllocator &  alloc)

Requests a block from.

Parameters
allocthe allocator
Returns

◆ size()

std::size_t bit::memory::memory_block_cache::size ( ) const
noexcept

Returns the number of memory_blocks in this cache.

This function is lazily computed, and is written with O(n) complexity

Returns
the number of memory_blocks in this cache

◆ size_bytes()

std::size_t bit::memory::memory_block_cache::size_bytes ( ) const
noexcept

Returns the size in bytes of all the memory_blocks in the cache.

Returns
the size in bytes

◆ steal_block()

void bit::memory::memory_block_cache::steal_block ( memory_block_cache other)
noexcept

Acquires an entry from another cache.

Parameters
otherthe cache to acquire the entry from

◆ store_block()

void bit::memory::memory_block_cache::store_block ( owner< memory_block block)
noexcept

Stores an allocated block inside this memory_block_cache.

Precondition
block.data() points to memory that is aligned to at least alignof(memory_block) bytes.
block points to a valid memory_block
Parameters
blockthe block to store

◆ swap()

void bit::memory::memory_block_cache::swap ( memory_block_cache other)
noexcept

Swaps this with another block cache.

Parameters
otherthe other memory_block_cache to swap with

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