XII Release 0.1.0
Loading...
Searching...
No Matches
xiiLargeBlockAllocator< BlockSizeInByte > Class Template Reference

#include <LargeBlockAllocator.h>

Public Member Functions

 xiiLargeBlockAllocator (xiiStringView sName, xiiAllocator *pParent, xiiAllocatorTrackingMode mode=xiiAllocatorTrackingMode::Default)
template<typename T>
xiiDataBlock< T, BlockSizeInByte > AllocateBlock ()
template<typename T>
void DeallocateBlock (xiiDataBlock< T, BlockSizeInByte > &ref_block)
 Deallocates a previously allocated block.
xiiStringView GetName () const
 Returns the name of this allocator instance.
xiiAllocatorId GetId () const
 Returns the unique identifier for this allocator instance.
const xiiAllocator::Stats & GetStats () const
template<typename T>
XII_FORCE_INLINE xiiDataBlock< T, BlockSize > AllocateBlock ()
template<typename T>
XII_FORCE_INLINE void DeallocateBlock (xiiDataBlock< T, BlockSize > &inout_block)

Detailed Description

template<xiiUInt32 BlockSizeInByte>
class xiiLargeBlockAllocator< BlockSizeInByte >

Specialized allocator for fixed-size memory blocks, optimized for bulk allocations.

This allocator manages memory in large chunks called "SuperBlocks" (16 blocks each) and provides individual blocks of the specified size on demand. It's designed for scenarios where you need many identically-sized allocations with good spatial locality.

SuperBlock strategy reduces fragmentation and improves cache performance by grouping related allocations together. When blocks are freed, they're added to a free list for immediate reuse without returning memory to the OS.

Best used for:

  • Object pools where objects have uniform size
  • Bulk allocations for data structures like arrays or strings
  • Memory regions that benefit from spatial locality

Member Function Documentation

◆ AllocateBlock()

template<xiiUInt32 BlockSizeInByte>
template<typename T>
xiiDataBlock< T, BlockSizeInByte > xiiLargeBlockAllocator< BlockSizeInByte >::AllocateBlock ( )

Allocates a new typed block capable of holding elements of type T.

Returns a typed wrapper around a raw memory block. The block can hold BlockSizeInByte / sizeof(T) elements. If allocation fails, returns an invalid block (check with IsEmpty()).


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