ULIS  dev4.0.7
Utility Library for Imaging Systems
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
FFixedAllocArena Class Reference

The FFixedAllocArena class is a class that provides a single configurable Arena buffer that manages allocations of fixed size. It is meant to be used for tiles or any objects of fixed size. More...

Public Member Functions

 FFixedAllocArena (byte_t iAllocSize, uint64 iNumCells)
 
 FFixedAllocArena (byte_t iArenaSize, byte_t iAllocSize)
 
 FFixedAllocArena (const FFixedAllocArena &)=delete
 
 ~FFixedAllocArena ()
 
byte_t AllocSize () const
 
byte_t ArenaSize () const
 
void DebugPrint () const
 
bool IsEmpty () const
 
bool IsFull () const
 
tClient Malloc ()
 
uint64 NumCells () const
 
uint64 NumFreeCells () const
 
uint64 NumUsedCells () const
 
ufloat OccupationRate () const
 
FFixedAllocArenaoperator= (const FFixedAllocArena &)=delete
 
void UnsafeFreeAll ()
 

Static Public Member Functions

static void Free (tClient iClient)
 

Friends

class FFixedAllocMemoryPool
 Friend FFixedAllocMemoryPool as it drives the Arena and might need to acces private methods. More...
 

Detailed Description

FFixedAllocArena allocs fixed allocations inside its block, and returns "clients" to the allocation, that is, a pointer to an allocation. Using such clients allows us to regularly defragment the Arena, or multiple Arenas if used in a pool, without losing the data if moved to another memory sector.

The Arena block allocates extra bytes to store some information about the memory status and allocation status, to ensure a fixed number of fixed allocations cells are available.

The layout of the buffer is like so:

FFixedAllocArena has public methods to estimate the local fragmentation of the memory. To be precise, there is no issue with fragmentation within a single Arena, but it is still possible to measure the sparsity of the allocations. Fragmentation becomes a problem when many arenas are sparse, hence wasting a lot of space.

A bit of Terminology:

Constructor & Destructor Documentation

◆ ~FFixedAllocArena()

FFixedAllocArena::~FFixedAllocArena ( )

Destructor, destroy the arena. Cleanup the underlying arena block. Make sure all allocations are free before destroying an arena, or it will trigger an assert in debug builds. You can use UnsafeFreeAll() before destruction to ensure it doesn't crash, but only if you know what you're doing. It is possible to do so before program termination, but if clients don't expect this, they will all be deleted without notification and induce a corrupted state within the program.

◆ FFixedAllocArena() [1/3]

FFixedAllocArena::FFixedAllocArena ( byte_t  iArenaSize,
byte_t  iAllocSize 
)
explicit

Constructor from arena size and alloc size. Make sure to chose an arena size that is greater than the alloc size and that can fit an expected number of fixed cells allocations. It is best to chose an alloc size that is a divisor of arena size, the behaviour is undefined otherwise.

◆ FFixedAllocArena() [2/3]

FFixedAllocArena::FFixedAllocArena ( byte_t  iAllocSize,
uint64  iNumCells 
)
explicit

Constructor from alloc size and number of expected cells or allocs. An arena size will be coomputed so that it can fit an expected number of fixed cells allocations.

◆ FFixedAllocArena() [3/3]

FFixedAllocArena::FFixedAllocArena ( const FFixedAllocArena )
delete

Explicitely deleted copy constructor

Member Function Documentation

◆ AllocSize()

byte_t FFixedAllocArena::AllocSize ( ) const

Obtain the alloc size in bytes

◆ ArenaSize()

byte_t FFixedAllocArena::ArenaSize ( ) const

Obtain the arena size in bytes

◆ DebugPrint()

void FFixedAllocArena::DebugPrint ( ) const

Get a textual representation of the arena for debug purposes.

◆ Free()

static void FFixedAllocArena::Free ( tClient  iClient)
static

Free an allocation and its associated client. It doesn't need to be resident in this arena.

◆ IsEmpty()

bool FFixedAllocArena::IsEmpty ( ) const

Checks wether the arena is empty or not.

◆ IsFull()

bool FFixedAllocArena::IsFull ( ) const

Checks wether the arena is full or not.

◆ Malloc()

tClient FFixedAllocArena::Malloc ( )

Obtain an client to an allocation within this arena. If full or a failure occurs, returns nullptr.

◆ NumCells()

uint64 FFixedAllocArena::NumCells ( ) const

Obtain the number of total possible cells in the arena.

◆ NumFreeCells()

uint64 FFixedAllocArena::NumFreeCells ( ) const

Obtain the number of currently free cells in the arena.

◆ NumUsedCells()

uint64 FFixedAllocArena::NumUsedCells ( ) const

Obtain the number of currently used cells in the arena.

◆ OccupationRate()

ufloat FFixedAllocArena::OccupationRate ( ) const

Determine the local occupation rate of the the allocations within the arena. From 0 to 1. 0: empty 1: full Local fragmentation within a single arena is irrelevant, but the ability to determine the Occupation of fixed allocations within an arena matters when used in a pool, with many arenas. A high global average occupation rate indicates the allocs are efficiently packed, whereas a low occupation rate indicates it's possiblle to concatenate arenas together and hence save space in a pool.

◆ operator=()

FFixedAllocArena& FFixedAllocArena::operator= ( const FFixedAllocArena )
delete

Explicitely deleted copy assignment operator

◆ UnsafeFreeAll()

void FFixedAllocArena::UnsafeFreeAll ( )

Free all resident allocations in this arena. Clients are deleted and not notified about their status. This is unsafe and dangerous, unless you're done with all clients.

Friends And Related Function Documentation

◆ FFixedAllocMemoryPool

friend class FFixedAllocMemoryPool
friend