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

union  BinIndex
 
struct  RangeAllocatorNode
 

Public Member Functions

 RangeAllocator ()
 Default constructor.
 
 RangeAllocator (uint 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 (uint size, uint alignment=1)
 Allocate range.
 
void Dealloc (const RangeAllocation &allocation)
 Deallocate range.
 

Private Member Functions

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

Static Private Member Functions

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

Private Attributes

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

Static Private Attributes

static constexpr uint NUM_BUCKETS = 0x20
 
static constexpr uint NUM_BINS_PER_BUCKET = 0x10
 

Constructor & Destructor Documentation

◆ RangeAllocator() [1/2]

Memory::RangeAllocator::RangeAllocator ( )
inline

Default constructor.

◆ RangeAllocator() [2/2]

Memory::RangeAllocator::RangeAllocator ( uint 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 ( uint size,
uint 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 ( uint size)
inlinestaticprivate

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 ( uint size,
bool round = false )
inlinestaticprivate

Get bin index from size.

◆ InsertNode()

uint Memory::RangeAllocator::InsertNode ( uint size,
uint 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]
private

◆ binMasks

uint Memory::RangeAllocator::binMasks[NUM_BUCKETS]
private

◆ bucketUsageMask

uint Memory::RangeAllocator::bucketUsageMask
private

◆ freeNodeIterator

uint Memory::RangeAllocator::freeNodeIterator
private

◆ freeNodes

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

◆ freeStorage

uint Memory::RangeAllocator::freeStorage
private

◆ nodes

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

◆ NUM_BINS_PER_BUCKET

uint Memory::RangeAllocator::NUM_BINS_PER_BUCKET = 0x10
staticconstexprprivate

◆ NUM_BUCKETS

uint Memory::RangeAllocator::NUM_BUCKETS = 0x20
staticconstexprprivate

◆ size

uint Memory::RangeAllocator::size
private

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