Foundation
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Foundation::Rendering::VirtualAllocator Class Reference

Thread-safe wrapper around VulkanMemoryAllocator's Virtual Allocator interface. More...

#include <VirtualAllocator.hpp>

Public Member Functions

 VirtualAllocator (size_t size, Allocator *alloc)
 Construct a VirtualAllocator instance.
 
VirtualAllocation Allocate (size_t size, size_t alignment)
 Allocate memory of size and alignment.
 
void Free (VirtualAllocation handle)
 Free a previous allocation.
 
Pair< size_t, size_tQuery (VirtualAllocation handle)
 Query the offset and size of a previous allocation.
 
size_t QuerySize (size_t handle)
 
size_t QueryOffset (size_t handle)
 
 ~VirtualAllocator ()
 

Private Attributes

const size_t mSize
 
VmaVirtualBlock mBlock {}
 
Pool< VirtualAllocation, Tuple< size_t, size_t, VmaVirtualAllocation > > mAllocs
 
Async::Mutex mMutex
 

Detailed Description

Thread-safe wrapper around VulkanMemoryAllocator's Virtual Allocator interface.

Note
Despite the name, this does not limit you to only Vulkan memory allocations. VMA's virtual allocations are just offsets into a large virtual memory arena that you can use for any purpose. The backing memory doesn't have to be real in that sense.

You can use this to allocate offsets into a large GPU buffer, or even as a general purpose CPU memory allocator - the usage of the latter is discouraged in favor of HeapAllocator and StackAllocator

See also

Constructor & Destructor Documentation

◆ VirtualAllocator()

Foundation::Rendering::VirtualAllocator::VirtualAllocator ( size_t  size,
Allocator alloc 
)

Construct a VirtualAllocator instance.

Parameters
sizeSize of the virtual memory arena
allocAllocator for virtual allocator state management

◆ ~VirtualAllocator()

Foundation::Rendering::VirtualAllocator::~VirtualAllocator ( )

Member Function Documentation

◆ Allocate()

VirtualAllocation Foundation::Rendering::VirtualAllocator::Allocate ( size_t  size,
size_t  alignment 
)

Allocate memory of size and alignment.

Parameters
sizeSize of the allocation
alignmentAlignment of the allocation
Returns
Opaque VirtualAllocation handle that you can use with Query, Free

◆ Free()

void Foundation::Rendering::VirtualAllocator::Free ( VirtualAllocation  handle)

Free a previous allocation.

Parameters
handlePreviously acquired allocation from the same allocator through Allocate

◆ Query()

Pair< size_t, size_t > Foundation::Rendering::VirtualAllocator::Query ( VirtualAllocation  handle)

Query the offset and size of a previous allocation.

Parameters
handlePreviously acquired allocation from the same allocator through Allocate
Returns
Pair of [Raw Offset, Raw Size]

◆ QueryOffset()

size_t Foundation::Rendering::VirtualAllocator::QueryOffset ( size_t  handle)
inline

◆ QuerySize()

size_t Foundation::Rendering::VirtualAllocator::QuerySize ( size_t  handle)
inline

Member Data Documentation

◆ mAllocs

Pool<VirtualAllocation, Tuple<size_t, size_t, VmaVirtualAllocation> > Foundation::Rendering::VirtualAllocator::mAllocs
private

◆ mBlock

VmaVirtualBlock Foundation::Rendering::VirtualAllocator::mBlock {}
private

◆ mMutex

Async::Mutex Foundation::Rendering::VirtualAllocator::mMutex
private

◆ mSize

const size_t Foundation::Rendering::VirtualAllocator::mSize
private

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