Nebula
Loading...
Searching...
No Matches
Memory::RangeAllocator Class Reference

#include <rangeallocator.h>

Detailed Description

Allocates memory ranges using the TLSF method, with extended handling of padding to better suit GPUs.

Doesn't manage memory itself but is meant to be used with a memory allocation/buffer of maxSize. Fast O(1) insertion and deletion and with minimal fragmentation.

More details: http://www.gii.upv.es/tlsf/files/ecrts04_tlsf.pdf

Classes

struct  RangeAllocatorNode
struct  BinIndex

Public Member Functions

 RangeAllocator ()
 Default constructor.
 RangeAllocator (size_t size, SizeT maxNumAllocs)
 Construct with predetermined size and max allowed number of allocations.
 ~RangeAllocator ()
 Destructor.
void Clear ()
 Clears the allocator.
bool Empty ()
 Checks if the allocator is empty.
RangeAllocation Alloc (size_t size, size_t alignment=1)
 Allocate range.
void Dealloc (const RangeAllocation &allocation)
 Deallocate range.

Public Attributes

size_t size
size_t freeStorage
uint freeNodeIterator
uint numAllocs
uint bucketUsageMask
uint binMasks [NUM_BUCKETS]
uint binHeads [NUM_BUCKETS *NUM_BINS_PER_BUCKET]
Util::Array< RangeAllocatorNodenodes
Util::Array< uintfreeNodes

Static Public Attributes

static constexpr uint NUM_BUCKETS = 32u
static constexpr uint NUM_BINS_PER_BUCKET = 8u

Private Member Functions

uint InsertNode (size_t size, size_t offset)
 Insert node at bin location, return node index.
void RemoveNode (uint nodeIndex)
 Remove node from bin.

Static Private Member Functions

static BinIndex IndexFromSize (size_t size, bool round=false)
 Get bin index from size.
static uint BucketFromSize (size_t size)
 Get bucket from index.
static uint BinFromSize (uint size, uint bucket)
 Get bin from index.

Constructor & Destructor Documentation

◆ RangeAllocator() [1/2]

Memory::RangeAllocator::RangeAllocator ( )
inline

Default constructor.

◆ RangeAllocator() [2/2]

Memory::RangeAllocator::RangeAllocator ( size_t size,
SizeT maxNumAllocs )
inline

Construct with predetermined size and max allowed number of allocations.

◆ ~RangeAllocator()

Memory::RangeAllocator::~RangeAllocator ( )
inline

Destructor.

Member Function Documentation

◆ Alloc()

RangeAllocation Memory::RangeAllocator::Alloc ( size_t size,
size_t alignment = 1 )
inline

Allocate range.

Returns a range using the TLSF method.

Note
Note that this doesn't actually allocate any memory, but instead returns a partial range within [0 -> size] that you can use with an external buffer to keep track of memory chunks

◆ BinFromSize()

uint Memory::RangeAllocator::BinFromSize ( uint size,
uint bucket )
inlinestaticprivate

Get bin from index.

◆ BucketFromSize()

uint Memory::RangeAllocator::BucketFromSize ( size_t size)
staticprivate

Get bucket from index.

◆ Clear()

void Memory::RangeAllocator::Clear ( )
inline

Clears the allocator.

◆ Dealloc()

void Memory::RangeAllocator::Dealloc ( const RangeAllocation & allocation)
inline

Deallocate range.

◆ Empty()

bool Memory::RangeAllocator::Empty ( )
inline

Checks if the allocator is empty.

◆ IndexFromSize()

RangeAllocator::BinIndex Memory::RangeAllocator::IndexFromSize ( size_t size,
bool round = false )
inlinestaticprivate

Get bin index from size.

◆ InsertNode()

uint Memory::RangeAllocator::InsertNode ( size_t size,
size_t offset )
inlineprivate

Insert node at bin location, return node index.

◆ RemoveNode()

void Memory::RangeAllocator::RemoveNode ( uint nodeIndex)
inlineprivate

Remove node from bin.

Member Data Documentation

◆ binHeads

uint Memory::RangeAllocator::binHeads[NUM_BUCKETS *NUM_BINS_PER_BUCKET]

◆ binMasks

uint Memory::RangeAllocator::binMasks[NUM_BUCKETS]

◆ bucketUsageMask

uint Memory::RangeAllocator::bucketUsageMask

◆ freeNodeIterator

uint Memory::RangeAllocator::freeNodeIterator

◆ freeNodes

Util::Array<uint> Memory::RangeAllocator::freeNodes

◆ freeStorage

size_t Memory::RangeAllocator::freeStorage

◆ nodes

Util::Array<RangeAllocatorNode> Memory::RangeAllocator::nodes

◆ NUM_BINS_PER_BUCKET

uint Memory::RangeAllocator::NUM_BINS_PER_BUCKET = 8u
staticconstexpr

◆ NUM_BUCKETS

uint Memory::RangeAllocator::NUM_BUCKETS = 32u
staticconstexpr

◆ numAllocs

uint Memory::RangeAllocator::numAllocs

◆ size

size_t Memory::RangeAllocator::size

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