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

The FShrinkableAllocMemoryPool class is a class that provides a configurable pool of shrinkable alloc arenas buffer to manages allocations with known maximum 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 RLE Compressed tiles or any objects of known maximal size, potentialy shrinkable, and can be driven asynchronously by a larger system if necessary. More...

Public Member Functions

 FShrinkableAllocMemoryPool (byte_t iArenaSize, byte_t iMaxAllocSize, byte_t iTargetMemoryUsage=1, ufloat iDefragThreshold=1/3.f, const FMemoryPoolPolicy &iPolicy=FMemoryPoolPolicy::PermissiveGrowth)
 
 FShrinkableAllocMemoryPool (byte_t iMaxAllocSize, uint64 iNumCellPerArena, byte_t iTargetMemoryUsage=1, ufloat iDefragThreshold=1/3.f, const FMemoryPoolPolicy &iPolicy=FMemoryPoolPolicy::PermissiveGrowth)
 
 FShrinkableAllocMemoryPool (const FShrinkableAllocMemoryPool &)=delete
 
 ~FShrinkableAllocMemoryPool ()
 
uint64 AllocArenasToReachTargetMemory ()
 
bool AllocOneArenaIfNecessary ()
 
byte_t ArenaSize () const
 
void DebugPrint (int iType=0, int iCol=100) const
 
void DefragForce ()
 
void DefragIfNecessary ()
 
float DefragThreshold () const
 
ufloat Fragmentation () const
 
uint64 FreeAllEmptyArenas ()
 
uint64 FreeEmptyArenasAccordingToPredicate (std::function< bool() > iPredicate)
 
uint64 FreeEmptyArenasToReachTargetMemory ()
 
byte_t FreeMemory () const
 
bool FreeOneArenaIfNecessary ()
 
tClient Malloc (byte_t iAllocSize=0xFFFFFFFF)
 
byte_t MaxAllocSize () const
 
FMemoryPoolPolicyMemoryPolicy ()
 
const FMemoryPoolPolicyMemoryPolicy () const
 
FShrinkableAllocMemoryPooloperator= (const FShrinkableAllocMemoryPool &)=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

FShrinkableAllocMemoryPool allows to obtain shrinkable allocations 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 FShrinkableAllocArena, but the pool aggregates them in a list and manages fragmentation and higher level systems and algorithms to drive them efficiently.

Constructor & Destructor Documentation

◆ ~FShrinkableAllocMemoryPool()

FShrinkableAllocMemoryPool::~FShrinkableAllocMemoryPool ( )

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.

◆ FShrinkableAllocMemoryPool() [1/3]

FShrinkableAllocMemoryPool::FShrinkableAllocMemoryPool ( byte_t  iArenaSize,
byte_t  iMaxAllocSize,
byte_t  iTargetMemoryUsage = 1,
ufloat  iDefragThreshold = 1/3.f,
const FMemoryPoolPolicy iPolicy = FMemoryPoolPolicy::PermissiveGrowth 
)
explicit

Constructor from arena size and max 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.

◆ FShrinkableAllocMemoryPool() [2/3]

FShrinkableAllocMemoryPool::FShrinkableAllocMemoryPool ( byte_t  iMaxAllocSize,
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 max size cells allocations.

◆ FShrinkableAllocMemoryPool() [3/3]

FShrinkableAllocMemoryPool::FShrinkableAllocMemoryPool ( const FShrinkableAllocMemoryPool )
delete

Explicitely deleted copy constructor

Member Function Documentation

◆ AllocArenasToReachTargetMemory()

uint64 FShrinkableAllocMemoryPool::AllocArenasToReachTargetMemory ( )

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

◆ AllocOneArenaIfNecessary()

bool FShrinkableAllocMemoryPool::AllocOneArenaIfNecessary ( )

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

◆ ArenaSize()

byte_t FShrinkableAllocMemoryPool::ArenaSize ( ) const

Obtain the arena size in bytes

◆ DebugPrint()

void FShrinkableAllocMemoryPool::DebugPrint ( int  iType = 0,
int  iCol = 100 
) const

Get a textual representation of the arena for debug purposes.

◆ DefragForce()

void FShrinkableAllocMemoryPool::DefragForce ( )

Force trigger a defrag.

◆ DefragIfNecessary()

void FShrinkableAllocMemoryPool::DefragIfNecessary ( )

Trigger a defrag only if the threshold is reached.

◆ DefragThreshold()

float FShrinkableAllocMemoryPool::DefragThreshold ( ) const

Get the defrag theshold.

◆ Fragmentation()

ufloat FShrinkableAllocMemoryPool::Fragmentation ( ) const

Arbitrary heuristic to estimate fragmentation of the pool.

◆ Free()

static void FShrinkableAllocMemoryPool::Free ( tClient  iClient)
static

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

◆ FreeAllEmptyArenas()

uint64 FShrinkableAllocMemoryPool::FreeAllEmptyArenas ( )

Free all arenas that are empty.

◆ FreeEmptyArenasAccordingToPredicate()

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

Free arenas according to predicate.

◆ FreeEmptyArenasToReachTargetMemory()

uint64 FShrinkableAllocMemoryPool::FreeEmptyArenasToReachTargetMemory ( )

Free all arenas that are empty.

◆ FreeMemory()

byte_t FShrinkableAllocMemoryPool::FreeMemory ( ) const

Obtain current free memory as bytes.

◆ FreeOneArenaIfNecessary()

bool FShrinkableAllocMemoryPool::FreeOneArenaIfNecessary ( )

Delete empty arena page if target memory is reached.

◆ Malloc()

tClient FShrinkableAllocMemoryPool::Malloc ( byte_t  iAllocSize = 0xFFFFFFFF)

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

◆ MaxAllocSize()

byte_t FShrinkableAllocMemoryPool::MaxAllocSize ( ) const

Obtain the alloc size in bytes

◆ MemoryPolicy() [1/2]

FMemoryPoolPolicy& FShrinkableAllocMemoryPool::MemoryPolicy ( )

Get modifiable Memory Policy.

◆ MemoryPolicy() [2/2]

const FMemoryPoolPolicy& FShrinkableAllocMemoryPool::MemoryPolicy ( ) const

Get const Memory Policy.

◆ operator=()

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

Explicitely deleted copy assignment operator

◆ SetDefragThreshold()

void FShrinkableAllocMemoryPool::SetDefragThreshold ( ufloat  iValue)

Set the defrag theshold.

◆ SetTargetMemoryUsage()

void FShrinkableAllocMemoryPool::SetTargetMemoryUsage ( byte_t  iValue)

Set the target memory usage as bytes.

◆ TargetMemoryUsage()

byte_t FShrinkableAllocMemoryPool::TargetMemoryUsage ( ) const

Obtain the target memory usage as bytes.

◆ TotalMemory()

byte_t FShrinkableAllocMemoryPool::TotalMemory ( ) const

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

◆ UnsafeFreeAll()

void FShrinkableAllocMemoryPool::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 FShrinkableAllocMemoryPool::UsedMemory ( ) const

Obtain current used memory as bytes.