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

The FFixedAllocMemoryPool class is a class that provides a configurable pool of fixed alloc arenas buffer to manages allocations of fixed size data efficiently and optimize memory consumption by evaluating sparsity, occupation and fragmentation of the various arena pages and concatenate them if neccessary. It is meant to be used for tiles or any objects of fixed size, and can be driven asynchronously by a larger system if necessary. More...

Public Member Functions

 FFixedAllocMemoryPool (byte_t iAllocSize, uint64 iNumCellPerArena, byte_t iTargetMemoryUsage=1, ufloat iDefragThreshold=1/3.f, const FMemoryPoolPolicy &iPolicy=FMemoryPoolPolicy::PermissiveGrowth)
 
 FFixedAllocMemoryPool (byte_t iArenaSize, byte_t iAllocSize, byte_t iTargetMemoryUsage=1, ufloat iDefragThreshold=1/3.f, const FMemoryPoolPolicy &iPolicy=FMemoryPoolPolicy::PermissiveGrowth)
 
 FFixedAllocMemoryPool (const FFixedAllocMemoryPool &)=delete
 
 ~FFixedAllocMemoryPool ()
 
uint64 AllocArenasToReachTargetMemory ()
 
bool AllocOneArenaIfNecessary ()
 
byte_t AllocSize () const
 
byte_t ArenaSize () const
 
void DebugPrint () const
 
void DefragForce ()
 
void DefragIfNecessary ()
 
ufloat DefragThreshold () const
 
ufloat Fragmentation () const
 
uint64 FreeAllEmptyArenas ()
 
uint64 FreeEmptyArenasAccordingToPredicate (std::function< bool() > iPredicate)
 
uint64 FreeEmptyArenasToReachTargetMemory ()
 
byte_t FreeMemory () const
 
bool FreeOneArenaIfNecessary ()
 
tClient Malloc ()
 
FMemoryPoolPolicyMemoryPolicy ()
 
const FMemoryPoolPolicyMemoryPolicy () const
 
uint64 NumCells () const
 
uint64 NumFreeCells () const
 
uint64 NumUsedCells () const
 
FFixedAllocMemoryPooloperator= (const FFixedAllocMemoryPool &)=delete
 
void SetDefragThreshold (ufloat iValue)
 
void SetTargetMemoryUsage (byte_t iValue)
 
byte_t TargetMemoryUsage () const
 
byte_t TotalMemory () const
 
void UnsafeFreeAll ()
 
byte_t UsedMemory () const
 

Static Public Member Functions

static void Free (tClient iClient)
 

Detailed Description

FFixedAllocMemoryPool allows to obtain fixed allocations inside that are resident of one arena page underlying block. It returns "clients" of the allocation, that is, a pointer to an allocation. The API is mostly similar to FFixedAllocArena, but the pool aggregates them in a list and manages fragmentation and higher level systems and algorithms to drive them efficiently.

Constructor & Destructor Documentation

◆ ~FFixedAllocMemoryPool()

FFixedAllocMemoryPool::~FFixedAllocMemoryPool ( )

Destructor, destroy the arenas pages. Cleanup the underlying arenas block. Make sure all allocations are free before destroying a pool, 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.

◆ FFixedAllocMemoryPool() [1/3]

FFixedAllocMemoryPool::FFixedAllocMemoryPool ( byte_t  iArenaSize,
byte_t  iAllocSize,
byte_t  iTargetMemoryUsage = 1,
ufloat  iDefragThreshold = 1/3.f,
const FMemoryPoolPolicy iPolicy = FMemoryPoolPolicy::PermissiveGrowth 
)
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.

◆ FFixedAllocMemoryPool() [2/3]

FFixedAllocMemoryPool::FFixedAllocMemoryPool ( byte_t  iAllocSize,
uint64  iNumCellPerArena,
byte_t  iTargetMemoryUsage = 1,
ufloat  iDefragThreshold = 1/3.f,
const FMemoryPoolPolicy iPolicy = FMemoryPoolPolicy::PermissiveGrowth 
)
explicit

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

◆ FFixedAllocMemoryPool() [3/3]

FFixedAllocMemoryPool::FFixedAllocMemoryPool ( const FFixedAllocMemoryPool )
delete

Explicitely deleted copy constructor

Member Function Documentation

◆ AllocArenasToReachTargetMemory()

uint64 FFixedAllocMemoryPool::AllocArenasToReachTargetMemory ( )

Alloc N empty arenas until memory target is reached. Return the number of allocated arenas.

◆ AllocOneArenaIfNecessary()

bool FFixedAllocMemoryPool::AllocOneArenaIfNecessary ( )

Alloc empty arena page if target memory isn't reached.

◆ AllocSize()

byte_t FFixedAllocMemoryPool::AllocSize ( ) const

Obtain the alloc size in bytes

◆ ArenaSize()

byte_t FFixedAllocMemoryPool::ArenaSize ( ) const

Obtain the arena size in bytes

◆ DebugPrint()

void FFixedAllocMemoryPool::DebugPrint ( ) const

Get a textual representation of the arena for debug purposes.

◆ DefragForce()

void FFixedAllocMemoryPool::DefragForce ( )

Force trigger a defrag.

◆ DefragIfNecessary()

void FFixedAllocMemoryPool::DefragIfNecessary ( )

Trigger a defrag only if the threshold is reached.

◆ DefragThreshold()

ufloat FFixedAllocMemoryPool::DefragThreshold ( ) const

Get the defrag theshold.

◆ Fragmentation()

ufloat FFixedAllocMemoryPool::Fragmentation ( ) const

Arbitrary heuristic to estimate fragmentation of the pool.

◆ Free()

static void FFixedAllocMemoryPool::Free ( tClient  iClient)
static

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

◆ FreeAllEmptyArenas()

uint64 FFixedAllocMemoryPool::FreeAllEmptyArenas ( )

Free all arenas that are empty.

◆ FreeEmptyArenasAccordingToPredicate()

uint64 FFixedAllocMemoryPool::FreeEmptyArenasAccordingToPredicate ( std::function< bool() >  iPredicate)

Free arenas according to predicate.

◆ FreeEmptyArenasToReachTargetMemory()

uint64 FFixedAllocMemoryPool::FreeEmptyArenasToReachTargetMemory ( )

Free all arenas that are empty.

◆ FreeMemory()

byte_t FFixedAllocMemoryPool::FreeMemory ( ) const

Obtain current free memory as bytes.

◆ FreeOneArenaIfNecessary()

bool FFixedAllocMemoryPool::FreeOneArenaIfNecessary ( )

Delete empty arena page if target memory is reached.

◆ Malloc()

tClient FFixedAllocMemoryPool::Malloc ( )

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

◆ MemoryPolicy() [1/2]

FMemoryPoolPolicy& FFixedAllocMemoryPool::MemoryPolicy ( )

Get modifiable Memory Policy.

◆ MemoryPolicy() [2/2]

const FMemoryPoolPolicy& FFixedAllocMemoryPool::MemoryPolicy ( ) const

Get const Memory Policy.

◆ NumCells()

uint64 FFixedAllocMemoryPool::NumCells ( ) const

Obtain the number of total possible cells in the pool.

◆ NumFreeCells()

uint64 FFixedAllocMemoryPool::NumFreeCells ( ) const

Obtain the number of currently free cells in the pool.

◆ NumUsedCells()

uint64 FFixedAllocMemoryPool::NumUsedCells ( ) const

Obtain the number of currently used cells in the pool.

◆ operator=()

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

Explicitely deleted copy assignment operator

◆ SetDefragThreshold()

void FFixedAllocMemoryPool::SetDefragThreshold ( ufloat  iValue)

Set the defrag theshold.

◆ SetTargetMemoryUsage()

void FFixedAllocMemoryPool::SetTargetMemoryUsage ( byte_t  iValue)

Set the target memory usage as bytes.

◆ TargetMemoryUsage()

byte_t FFixedAllocMemoryPool::TargetMemoryUsage ( ) const

Obtain the target memory usage as bytes.

◆ TotalMemory()

byte_t FFixedAllocMemoryPool::TotalMemory ( ) const

Obtain the total theoretical memory for this pool as bytes, given the current number or arenas.

◆ UnsafeFreeAll()

void FFixedAllocMemoryPool::UnsafeFreeAll ( )

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

◆ UsedMemory()

byte_t FFixedAllocMemoryPool::UsedMemory ( ) const

Obtain current used memory as bytes.