Games Task Scheduler (GTS)
A multi-processor scheduling framework for games engines
gts::MemoryStore Struct Reference

The header for each Slab. More...

#include <BinnedAllocator.h>

Public Member Functions

GTS_INLINE bool init () const
 
bool empty () const
 
void clear ()
 Deallocates all slabs. More...
 
SlabHeader * allocateSlab (size_t pageSize)
 
void deallocateSlab (SlabHeader *pSlab, bool freeIt)
 
PageHeader * allocatePage (SlabHeader *pSlab, size_t blockSize)
 
void initPage (PageHeader *pPage, size_t pageSize, size_t blockSize)
 
void deallocatePage (PageHeader *pPage)
 

Static Public Member Functions

static GTS_INLINE SlabHeader * toSlab (void *ptr)
 
static GTS_INLINE PageHeader * toPage (SlabHeader *pSlab, void *ptr)
 
static GTS_INLINE void * toAlignedBlockStart (PageHeader *pPage, void *ptr)
 
static GTS_INLINE size_t pageSizeToIndex (size_t pageSize)
 

Static Public Attributes

static constexpr uint32_t SIZE_DIVISOR = 2
 
static constexpr uint32_t SLAB_SIZE = (4 * 1024 * 1024) / SIZE_DIVISOR
 The size of a the Slab used for all Page size classes.
 
static constexpr uint32_t PAGE_SIZE_CLASS_0 = (16 * 1024) / SIZE_DIVISOR
 
static constexpr uint32_t PAGE_SIZE_CLASS_1 = (64 * 1024) / SIZE_DIVISOR
 
static constexpr uint32_t PAGE_SIZE_CLASS_2 = (128 * 1024) / SIZE_DIVISOR
 
static constexpr uint32_t PAGE_SIZE_CLASS_3 = (512 * 1024) / SIZE_DIVISOR
 
static constexpr uint32_t PAGE_FREE_LISTS_COUNT = 5
 The number of free list, one for each page class size.
 
static const uint32_t SINGLE_PAGE_HEADER_SIZE
 The needed space for headers when allocating a Slab with a single Page.
 

Detailed Description

The header for each Slab.

The header for each Page.

Creates, destroys, and manages Pages and Slabs.

Member Function Documentation

◆ allocatePage()

PageHeader* gts::MemoryStore::allocatePage ( SlabHeader *  pSlab,
size_t  blockSize 
)

Commits a page from the Slab and initializes it.

◆ allocateSlab()

SlabHeader* gts::MemoryStore::allocateSlab ( size_t  pageSize)

Allocates a region of memory. Slabs are reserved as 4MiB unless 'pageSize' does not fit.

◆ clear()

void gts::MemoryStore::clear ( )

Deallocates all slabs.

Remarks
Not thread-safe.

◆ deallocatePage()

void gts::MemoryStore::deallocatePage ( PageHeader *  pPage)

Decommits a Page.

◆ deallocateSlab()

void gts::MemoryStore::deallocateSlab ( SlabHeader *  pSlab,
bool  freeIt 
)

Add a Slab to the free list. Frees Slabs larger than SLAB_SIZE.

◆ empty()

bool gts::MemoryStore::empty ( ) const
Returns
True if the store has no allocated slabs.
Remarks
Not thread-safe.

◆ initPage()

void gts::MemoryStore::initPage ( PageHeader *  pPage,
size_t  pageSize,
size_t  blockSize 
)

Initializes a Page.

◆ toAlignedBlockStart()

static GTS_INLINE void* gts::MemoryStore::toAlignedBlockStart ( PageHeader *  pPage,
void *  ptr 
)
inlinestatic
Returns
This aligned block actual start address.
Remarks
Thread-safe.

◆ toPage()

static GTS_INLINE PageHeader* gts::MemoryStore::toPage ( SlabHeader *  pSlab,
void *  ptr 
)
inlinestatic
Returns
This block's Page.
Remarks
Thread-safe.

◆ toSlab()

static GTS_INLINE SlabHeader* gts::MemoryStore::toSlab ( void *  ptr)
inlinestatic
Returns
This block's Slab.
Remarks
Thread-safe.