Games Task Scheduler (GTS)
A multi-processor scheduling framework for games engines
gts::internal::BlockAllocator Class Reference

Manages a list of Slab and Pages, and allocates and frees homogeneous Pages from Slabs and Blocks from Pages. More...

#include <BinnedAllocator.h>

Public Member Functions

GTS_INLINE BlockAllocator (BlockAllocator const &)
 
bool init (BinnedAllocator *pBinnedAllocator, size_type blockSize, size_type pageSize)
 
void shutdown ()
 
void * allocate ()
 
void deallocate (void *ptr)
 
GTS_INLINE size_type blockSize () const
 
GTS_INLINE size_type pageSize () const
 

Detailed Description

Manages a list of Slab and Pages, and allocates and frees homogeneous Pages from Slabs and Blocks from Pages.

Remarks
This class is not thread safe.

Member Function Documentation

◆ allocate()

void* gts::internal::BlockAllocator::allocate ( )
Returns
An 'allocationSize' chunk of memory.
Remarks
Not thread-safe.

◆ blockSize()

GTS_INLINE size_type gts::internal::BlockAllocator::blockSize ( ) const
inline
Returns
The size of each Block in a Page.
Remarks
Thread-safe.

◆ deallocate()

void gts::internal::BlockAllocator::deallocate ( void *  ptr)

Free the memory in ptr.

Parameters
workerIdThe ID of the calling Worker thread.
Remarks
Thread-safe.

◆ init()

bool gts::internal::BlockAllocator::init ( BinnedAllocator pBinnedAllocator,
size_type  blockSize,
size_type  pageSize 
)

Initialize the BlockAllocator. This must happen before calling allocate.

Parameters
pMemoryStoreThe source of memory for this allocator.
blockSizeThe size of each Block in a Page.
pageSizeThe size of each Page in a Slab.
Remarks
Not thread-safe.

◆ pageSize()

GTS_INLINE size_type gts::internal::BlockAllocator::pageSize ( ) const
inline
Returns
The size of each Page in a Slab.
Remarks
Thread-safe.

◆ shutdown()

void gts::internal::BlockAllocator::shutdown ( )

Returns all allocated memory back to the OS and checks for memory leaks.

Remarks
Not thread-safe.