Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Core::DescriptorIndexAllocator Class Reference

Use this class to manage a finite amount of memory. The idea is to have an array which stores objects and a vector which has pointers to said objects in the array. The array is sparsely populated using optionals. More...

#include <DescriptorIndexAllocator.h>

Collaboration diagram for Engine::Core::DescriptorIndexAllocator:

Public Member Functions

 DescriptorIndexAllocator ()=delete
 Default construction is disabled because the allocator needs a fixed capacity.
 DescriptorIndexAllocator (int descriptorCount)
 Creates an allocator with descriptor indices in the range [0, descriptorCount).
uint32_t allocate ()
 Get an index where there is no data in the array.
void reserve (uint32_t index)
 Marks a specific free index as allocated.
void free (uint32_t index)
 Frees a cell in the array where the memory is not used anymore.
const std::vector< uint32_t > & getUsedIndices () const
 Gets the indices of all allocated fields in the array.
void reset (int newSize)
 Resets all values in the buffers and allocates with new size.
size_t getCapacity () const
 Gets the number of descriptor indices managed by the allocator.

Private Attributes

std::stack< uint32_t > freeIndices
std::vector< uint32_t > usedIndices
uint32_t capacity

Detailed Description

Use this class to manage a finite amount of memory. The idea is to have an array which stores objects and a vector which has pointers to said objects in the array. The array is sparsely populated using optionals.

Definition at line 12 of file DescriptorIndexAllocator.h.

Constructor & Destructor Documentation

◆ DescriptorIndexAllocator() [1/2]

Engine::Core::DescriptorIndexAllocator::DescriptorIndexAllocator ( )
delete

Default construction is disabled because the allocator needs a fixed capacity.

◆ DescriptorIndexAllocator() [2/2]

Engine::Core::DescriptorIndexAllocator::DescriptorIndexAllocator ( int descriptorCount)
explicit

Creates an allocator with descriptor indices in the range [0, descriptorCount).

Parameters
descriptorCountNumber of descriptor indices managed by the allocator.

Member Function Documentation

◆ allocate()

uint32_t Engine::Core::DescriptorIndexAllocator::allocate ( )
nodiscard

Get an index where there is no data in the array.

Returns
an index in the array which does not have data
Exceptions
AllocationExceptionwhen there are no free elements left

◆ free()

void Engine::Core::DescriptorIndexAllocator::free ( uint32_t index)

Frees a cell in the array where the memory is not used anymore.

Parameters
indexthe index in the array to release back into the pool of free memory

◆ getCapacity()

size_t Engine::Core::DescriptorIndexAllocator::getCapacity ( ) const

Gets the number of descriptor indices managed by the allocator.

◆ getUsedIndices()

const std::vector< uint32_t > & Engine::Core::DescriptorIndexAllocator::getUsedIndices ( ) const
nodiscard

Gets the indices of all allocated fields in the array.

Returns
list of all indices of allocated cells in the array

◆ reserve()

void Engine::Core::DescriptorIndexAllocator::reserve ( uint32_t index)

Marks a specific free index as allocated.

Exceptions
std::invalid_argumentwhen the index is out of range or already allocated.

◆ reset()

void Engine::Core::DescriptorIndexAllocator::reset ( int newSize)

Resets all values in the buffers and allocates with new size.

Parameters
newSizeSize of the new allocator

Member Data Documentation

◆ capacity

uint32_t Engine::Core::DescriptorIndexAllocator::capacity
private

Definition at line 69 of file DescriptorIndexAllocator.h.

◆ freeIndices

std::stack<uint32_t> Engine::Core::DescriptorIndexAllocator::freeIndices
private

Definition at line 67 of file DescriptorIndexAllocator.h.

◆ usedIndices

std::vector<uint32_t> Engine::Core::DescriptorIndexAllocator::usedIndices
private

Definition at line 68 of file DescriptorIndexAllocator.h.


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