Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
gaia::mem::MemoryPage< T, RequestedBlockSize > Struct Template Reference

Fixed-capacity page of equal-sized blocks. More...

#include <paged_allocator.h>

+ Inheritance diagram for gaia::mem::MemoryPage< T, RequestedBlockSize >:

Public Types

using Page = MemoryPage< T, RequestedBlockSize >
 This page type.
 
using BlockArray = cnt::sarray< uint8_t, BlockArrayBytes >
 Packed block-index storage.
 
using BitView = core::bit_view< NBlocks_Bits >
 View used to read and write packed block indices.
 

Public Member Functions

 MemoryPage (void *ptr)
 Free bits to use in the future.
 
void write_block_idx (uint32_t blockIdx, uint32_t value)
 Writes one link in the packed recycled-block list.
 
uint8_t read_block_idx (uint32_t blockIdx) const
 Reads one link from the packed recycled-block list.
 
GAIA_NODISCARD void * alloc_block ()
 Allocate a new block for this page.
 
void free_block (void *pBlock)
 Release the block allocated by this page.
 
GAIA_NODISCARD uint32_t used_blocks_cnt () const
 Returns the number of live blocks.
 
GAIA_NODISCARD bool full () const
 Reports whether all page blocks are allocated.
 
GAIA_NODISCARD bool empty () const
 Reports whether no page blocks are allocated.
 
void verify () const
 Verifies page invariants in assertion-enabled builds.
 
- Public Member Functions inherited from gaia::mem::MemoryPageHeader
 MemoryPageHeader (void *ptr)
 Creates a page header for a backing allocation.
 
- Public Member Functions inherited from gaia::cnt::fwd_llist_base< MemoryPage< T, RequestedBlockSize > >
fwd_llist_link< MemoryPage< T, RequestedBlockSize > > & get_fwd_llist_link ()
 Returns the mutable intrusive link.
 
const fwd_llist_link< MemoryPage< T, RequestedBlockSize > > & get_fwd_llist_link () const
 Returns the immutable intrusive link.
 

Static Public Member Functions

static constexpr uint32_t next_multiple_of_alignment (uint32_t num)
 Rounds a size up to MemoryBlockAlignment.
 
static constexpr uint32_t calculate_block_size ()
 Selects and aligns the configured block size.
 

Public Attributes

BlockArray m_blocks
 Implicit list of blocks.
 
uint32_t m_blockCnt: NBlocks_Bits
 Number of blocks in the block array.
 
uint32_t m_usedBlocks: NBlocks_Bits
 Number of used blocks out of NBlocks.
 
uint32_t m_nextFreeBlock: NBlocks_Bits
 Index of the next block to recycle.
 
uint32_t m_freeBlocks: NBlocks_Bits
 Number of blocks to recycle.
 
- Public Attributes inherited from gaia::mem::MemoryPageHeader
void * m_data
 Pointer to data managed by page.
 
- Public Attributes inherited from gaia::cnt::fwd_llist_base< MemoryPage< T, RequestedBlockSize > >
fwd_llist_link< MemoryPage< T, RequestedBlockSize > > fwd_link_GAIA
 Intrusive link storage used by fwd_llist.
 

Static Public Attributes

static constexpr uint32_t MemoryBlockBytes = calculate_block_size()
 Size of one block in bytes.
 
static constexpr uint16_t NBlocks = 48
 Maximum number of blocks in a page.
 
static constexpr uint16_t NBlocks_Bits = (uint16_t)core::count_bits(NBlocks)
 Bits required to encode a block index.
 
static constexpr uint32_t InvalidBlockId = NBlocks + 1
 Sentinel terminating the recycled-block list.
 
static constexpr uint32_t BlockArrayBytes = ((uint32_t)NBlocks_Bits * (uint32_t)NBlocks + 7) / 8
 Bytes occupied by the packed block-index array.
 

Detailed Description

template<typename T, uint32_t RequestedBlockSize>
struct gaia::mem::MemoryPage< T, RequestedBlockSize >

Fixed-capacity page of equal-sized blocks.

Template Parameters
TAllocation category used for singleton separation and diagnostics.
RequestedBlockSizeRequested bytes per block, or zero for the default.

Constructor & Destructor Documentation

◆ MemoryPage()

template<typename T , uint32_t RequestedBlockSize>
gaia::mem::MemoryPage< T, RequestedBlockSize >::MemoryPage ( void *  ptr)
inline

Free bits to use in the future.

Creates an empty page over a backing allocation.

Parameters
ptrBacking allocation address.

Member Function Documentation

◆ alloc_block()

template<typename T , uint32_t RequestedBlockSize>
GAIA_NODISCARD void * gaia::mem::MemoryPage< T, RequestedBlockSize >::alloc_block ( )
inline

Allocate a new block for this page.

Returns
Pointer to the usable block storage.

◆ calculate_block_size()

template<typename T , uint32_t RequestedBlockSize>
static constexpr uint32_t gaia::mem::MemoryPage< T, RequestedBlockSize >::calculate_block_size ( )
inlinestaticconstexpr

Selects and aligns the configured block size.

Returns
Block size in bytes.

◆ empty()

template<typename T , uint32_t RequestedBlockSize>
GAIA_NODISCARD bool gaia::mem::MemoryPage< T, RequestedBlockSize >::empty ( ) const
inline

Reports whether no page blocks are allocated.

Returns
True when the page is empty.

◆ free_block()

template<typename T , uint32_t RequestedBlockSize>
void gaia::mem::MemoryPage< T, RequestedBlockSize >::free_block ( void *  pBlock)
inline

Release the block allocated by this page.

Parameters
pBlockPointer previously returned by alloc_block().

◆ full()

template<typename T , uint32_t RequestedBlockSize>
GAIA_NODISCARD bool gaia::mem::MemoryPage< T, RequestedBlockSize >::full ( ) const
inline

Reports whether all page blocks are allocated.

Returns
True when the page is full.

◆ next_multiple_of_alignment()

template<typename T , uint32_t RequestedBlockSize>
static constexpr uint32_t gaia::mem::MemoryPage< T, RequestedBlockSize >::next_multiple_of_alignment ( uint32_t  num)
inlinestaticconstexpr

Rounds a size up to MemoryBlockAlignment.

Parameters
numSize in bytes.
Returns
Aligned size in bytes.

◆ read_block_idx()

template<typename T , uint32_t RequestedBlockSize>
uint8_t gaia::mem::MemoryPage< T, RequestedBlockSize >::read_block_idx ( uint32_t  blockIdx) const
inline

Reads one link from the packed recycled-block list.

Parameters
blockIdxBlock whose link is read.
Returns
Linked block index or InvalidBlockId.

◆ used_blocks_cnt()

template<typename T , uint32_t RequestedBlockSize>
GAIA_NODISCARD uint32_t gaia::mem::MemoryPage< T, RequestedBlockSize >::used_blocks_cnt ( ) const
inline

Returns the number of live blocks.

Returns
Number of allocated blocks.

◆ write_block_idx()

template<typename T , uint32_t RequestedBlockSize>
void gaia::mem::MemoryPage< T, RequestedBlockSize >::write_block_idx ( uint32_t  blockIdx,
uint32_t  value 
)
inline

Writes one link in the packed recycled-block list.

Parameters
blockIdxBlock whose link is updated.
valueLinked block index or InvalidBlockId.

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