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...
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.
◆ ~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]
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]
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]
Explicitely deleted copy constructor
◆ 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 |
( |
| ) |
|
◆ DefragIfNecessary()
void FShrinkableAllocMemoryPool::DefragIfNecessary |
( |
| ) |
|
Trigger a defrag only if the threshold is reached.
◆ DefragThreshold()
float FShrinkableAllocMemoryPool::DefragThreshold |
( |
| ) |
const |
◆ 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]
Get modifiable Memory Policy.
◆ MemoryPolicy() [2/2]
◆ operator=()
Explicitely deleted copy assignment operator
◆ SetDefragThreshold()
void FShrinkableAllocMemoryPool::SetDefragThreshold |
( |
ufloat |
iValue | ) |
|
◆ 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.