TMemoryPool

Syntax

template<bool(*)(void *AddrStart, SIZE_T Size) CommitAddressRange, bool(*)(void *AddrStart, SIZE_T Size) EvictAddressRange, SIZE_T RequiredAlignment>
class TMemoryPool

Remarks

Class for managing allocations of the size no larger than BlockSize.

Variables

Name Description

Protected variable

SIZE_T

 

AlignedPoolEnd

End of the pool (an address in memory), cast to SIZE_T for arithmetic ops.

Protected variable

SIZE_T

 

AlignedPoolStart

Beginning of the pool (an address in memory), cast to SIZE_T for arithmetic ops.

Protected variable

uint8 *

 

Bitmask

A bit mask of the free blocks: 0 used, 1 free - because that way it's easier to scan

Protected variable

SIZE_T

 

BitmaskSizeInBytes

Size of the bitmask in bytes

Protected variable

SIZE_T

 

BlockSize

Size of a single block

Protected variable

SIZE_T

 

NumBlocks

Num of the blocks to cache

Protected variable

SIZE_T

 

NumFreeBlocks

Current length of the stack.

Protected variable

SIZE_T

 

UsefulMemorySize

When we're allocating less than block size, only BlockSize - Size is going to be used.

Constructors

Name Description

Public function

TMemoryPool

(
    SIZE_T InBlockSize,
    SIZE_T InAlignedPoolStart,
    SIZE_T InNumBlocks,
    uint8 * InBitmask
)

Functions

Name Description

Public function

void *

 

Allocate

(
    SIZE_T Size
)

We always allocate in BlockSize chunks, Size is only passed for more accurate Commit()

Public function Static

SIZE_T

 

BitmaskMemorySize

(
    SIZE_T NumBlocks
)

Public function

SIZE_T

 

CalculateFreeBlocksInBitmap()

Debugging function

Public function

bool

 

CanAllocateFromThisPool

(
    SIZE_T Size
)

Returns true if we can allocate this much memory from this pool.

Public function

void *

 

FindFirstFreeAndMarkUsed()

Public function

void

 

Free

(
    void* Ptr,
    SIZE_T Size
)

We always free BlockSize-d chunks.

Public function Const

uint64

 

GetAllocatableMemorySize()

Returns memory size that we can actually allocate from the pool (mostly for malloc stats)

Public function Const

uint64

 

GetOverheadSize()

Returns overhead caused by allocating less than BlockSize (mostly for malloc stats)

Public function Const

bool

 

IsEmpty()

Public function

void

 

MarkFree

(
    void* Ptr
)

Public function

void

 

PrintDebugInfo()

Public function

bool

 

WasAllocatedFromThisPool

(
    void* Ptr,
    SIZE_T Size
)

Returns true if this allocation came from this pool.

References

Module

Core

Header

Runtime/Core/Public/GenericPlatform/OSAllocationPool.h