LiteFX 0.5.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
LiteFX::Rendering::VirtualAllocator Class Referencefinal

Represents a virtual allocator that manages memory distribution from a piece of raw memory. More...

#include <rendering_api.hpp>

Classes

struct  Allocation
 Represents an allocation within the memory managed by the virtual allocator. More...
 

Public Member Functions

 VirtualAllocator (const VirtualAllocator &)=delete
 
 VirtualAllocator (VirtualAllocator &&) noexcept=delete
 
VirtualAllocatoroperator= (const VirtualAllocator &)=delete
 
VirtualAllocatoroperator= (VirtualAllocator &&) noexcept=delete
 
 ~VirtualAllocator () noexcept=default
 
UInt64 size () const noexcept
 Returns the size of the memory managed by the virtual allocator.
 
AllocationAlgorithm algorithm () const noexcept
 Returns the algorithm used by the allocator.
 
Allocation allocate (UInt64 size, UInt32 alignment=1u, AllocationStrategy strategy=AllocationStrategy::OptimizePacking, void *privateData=nullptr) const
 Allocates a piece of memory of size bytes, aligned to alignment .
 
void free (Allocation &&allocation) const
 Releases an allocation from the allocator, so that its memory can be re-used later.
 
void * privateData (const Allocation &allocation) const
 Returns the private data associated with an allocation.
 

Static Public Member Functions

template<typename TBackend >
static VirtualAllocator create (UInt64 overallMemory, AllocationAlgorithm algorithm=AllocationAlgorithm::Default)
 Creates a new virtual allocator instance.
 

Detailed Description

Represents a virtual allocator that manages memory distribution from a piece of raw memory.

Note that the virtual allocator does not actually contain memory, but rather keeps track over a range of memory that is externally managed.

Constructor & Destructor Documentation

◆ VirtualAllocator() [1/2]

LiteFX::Rendering::VirtualAllocator::VirtualAllocator ( const VirtualAllocator & )
delete

◆ VirtualAllocator() [2/2]

LiteFX::Rendering::VirtualAllocator::VirtualAllocator ( VirtualAllocator && )
deletenoexcept

◆ ~VirtualAllocator()

LiteFX::Rendering::VirtualAllocator::~VirtualAllocator ( )
defaultnoexcept

Member Function Documentation

◆ algorithm()

AllocationAlgorithm LiteFX::Rendering::VirtualAllocator::algorithm ( ) const
inlinenoexcept

Returns the algorithm used by the allocator.

Returns
The algorithm used by the allocator.

◆ allocate()

Allocation LiteFX::Rendering::VirtualAllocator::allocate ( UInt64 size,
UInt32 alignment = 1u,
AllocationStrategy strategy = AllocationStrategy::OptimizePacking,
void * privateData = nullptr ) const
inlinenodiscard

Allocates a piece of memory of size bytes, aligned to alignment .

Parameters
sizeThe size (in bytes) of the resource to place in the allocation.
alignmentThe alignment requirements of the resource.
strategyThe strategy to look for a place to put the allocation in.
privateDataA pointer to an object that should be internally associated with the allocation.
Returns
An object that contains details about the allocation.

◆ create()

template<typename TBackend >
static VirtualAllocator LiteFX::Rendering::VirtualAllocator::create ( UInt64 overallMemory,
AllocationAlgorithm algorithm = AllocationAlgorithm::Default )
inlinestaticnodiscard

Creates a new virtual allocator instance.

Parameters
overallMemoryThe overall size (in bytes) of memory available to the allocator.
algorithmThe algorithm used to find a suitable block in the allocator memory.
Returns
The instance of the virtual allocator.

◆ free()

void LiteFX::Rendering::VirtualAllocator::free ( Allocation && allocation) const
inline

Releases an allocation from the allocator, so that its memory can be re-used later.

Releasing an allocation that was not allocated from the virtual allocator is undefined behavior.

Parameters
allocationThe allocation to release.

◆ operator=() [1/2]

VirtualAllocator & LiteFX::Rendering::VirtualAllocator::operator= ( const VirtualAllocator & )
delete

◆ operator=() [2/2]

VirtualAllocator & LiteFX::Rendering::VirtualAllocator::operator= ( VirtualAllocator && )
deletenoexcept

◆ privateData()

void * LiteFX::Rendering::VirtualAllocator::privateData ( const Allocation & allocation) const
inline

Returns the private data associated with an allocation.

Parameters
allocationThe allocation for which to obtain the private data.
Returns
A pointer that references the private data associated with the allocation.

◆ size()

UInt64 LiteFX::Rendering::VirtualAllocator::size ( ) const
inlinenoexcept

Returns the size of the memory managed by the virtual allocator.

Returns
The size (in bytes) of the memory managed by the virtual allocator.