Direct3D 12 Memory Allocator
Loading...
Searching...
No Matches
Public Member Functions | List of all members
D3D12MA::VirtualBlock Class Reference

Represents pure allocation algorithm and a data structure with allocations in some memory block, without actually allocating any GPU memory. More...

#include <D3D12MemAlloc.h>

Inheritance diagram for D3D12MA::VirtualBlock:

Public Member Functions

BOOL IsEmpty () const
 Returns true if the block is empty - contains 0 allocations.
 
void GetAllocationInfo (VirtualAllocation allocation, VIRTUAL_ALLOCATION_INFO *pInfo) const
 Returns information about an allocation - its offset, size and custom pointer.
 
HRESULT Allocate (const VIRTUAL_ALLOCATION_DESC *pDesc, VirtualAllocation *pAllocation, UINT64 *pOffset)
 Creates new allocation.
 
void FreeAllocation (VirtualAllocation allocation)
 Frees the allocation.
 
void Clear ()
 Frees all the allocations.
 
void SetAllocationPrivateData (VirtualAllocation allocation, void *pPrivateData)
 Changes custom pointer for an allocation to a new value.
 
void GetStatistics (Statistics *pStats) const
 Retrieves basic statistics of the virtual block that are fast to calculate.
 
void CalculateStatistics (DetailedStatistics *pStats) const
 Retrieves detailed statistics of the virtual block that are slower to calculate.
 
void BuildStatsString (WCHAR **ppStatsString) const
 Builds and returns statistics as a string in JSON format, including the list of allocations with their parameters.
 
void FreeStatsString (WCHAR *pStatsString) const
 Frees memory of a string returned from VirtualBlock::BuildStatsString.
 

Detailed Description

Represents pure allocation algorithm and a data structure with allocations in some memory block, without actually allocating any GPU memory.

This class allows to use the core algorithm of the library custom allocations e.g. CPU memory or sub-allocation regions inside a single GPU buffer.

To create this object, fill in D3D12MA::VIRTUAL_BLOCK_DESC and call CreateVirtualBlock(). To destroy it, call its method VirtualBlock::Release(). You need to free all the allocations within this block or call Clear() before destroying it.

This object is not thread-safe - should not be used from multiple threads simultaneously, must be synchronized externally.

Member Function Documentation

◆ Allocate()

HRESULT D3D12MA::VirtualBlock::Allocate ( const VIRTUAL_ALLOCATION_DESC * pDesc,
VirtualAllocation * pAllocation,
UINT64 * pOffset )

Creates new allocation.

Parameters
pDesc
[out]pAllocationUnique indentifier of the new allocation within single block.
[out]pOffsetReturned offset of the new allocation. Optional, can be null.
Returns
S_OK if allocation succeeded, E_OUTOFMEMORY if it failed.

If the allocation failed, pAllocation->AllocHandle is set to 0 and pOffset, if not null, is set to UINT64_MAX.

◆ BuildStatsString()

void D3D12MA::VirtualBlock::BuildStatsString ( WCHAR ** ppStatsString) const

Builds and returns statistics as a string in JSON format, including the list of allocations with their parameters.

Parameters
[out]ppStatsStringMust be freed using VirtualBlock::FreeStatsString.

◆ CalculateStatistics()

void D3D12MA::VirtualBlock::CalculateStatistics ( DetailedStatistics * pStats) const

Retrieves detailed statistics of the virtual block that are slower to calculate.

Parameters
[out]pStatsStatistics of the virtual block.

◆ Clear()

void D3D12MA::VirtualBlock::Clear ( )

Frees all the allocations.

◆ FreeAllocation()

void D3D12MA::VirtualBlock::FreeAllocation ( VirtualAllocation allocation)

Frees the allocation.

Calling this function with allocation.AllocHandle == 0 is correct and does nothing.

◆ FreeStatsString()

void D3D12MA::VirtualBlock::FreeStatsString ( WCHAR * pStatsString) const

Frees memory of a string returned from VirtualBlock::BuildStatsString.

◆ GetAllocationInfo()

void D3D12MA::VirtualBlock::GetAllocationInfo ( VirtualAllocation allocation,
VIRTUAL_ALLOCATION_INFO * pInfo ) const

Returns information about an allocation - its offset, size and custom pointer.

◆ GetStatistics()

void D3D12MA::VirtualBlock::GetStatistics ( Statistics * pStats) const

Retrieves basic statistics of the virtual block that are fast to calculate.

Parameters
[out]pStatsStatistics of the virtual block.

◆ IsEmpty()

BOOL D3D12MA::VirtualBlock::IsEmpty ( ) const

Returns true if the block is empty - contains 0 allocations.

◆ SetAllocationPrivateData()

void D3D12MA::VirtualBlock::SetAllocationPrivateData ( VirtualAllocation allocation,
void * pPrivateData )

Changes custom pointer for an allocation to a new value.


The documentation for this class was generated from the following file: