vpr::Allocation class


Allocation class represents a singular allocation: can be a private allocation (i.e, only user of attached DeviceMemory) or a block allocation (bound to sub-region of device memory)

Constructors, destructors, conversion operators

Allocation()
If this is an allocation bound to a smaller region of a larger object, it is a block allocation.

Public functions

void Init(MemoryBlock* parent_block, const VkDeviceSize& offset, const VkDeviceSize& alignment, const VkDeviceSize& alloc_size, void* user_data = nullptr)
user_data can be a pointer to anything, but the lifetime of this pointer has to be managed by the user.
void Update(MemoryBlock* new_parent_block, const VkDeviceSize& new_offset)
Changes parent memory block, and specifies a new offset for the memory.
void InitPrivate(const uint32_t& type_idx, VkDeviceMemory& dvc_memory, bool persistently_mapped, void* mapped_data, const VkDeviceSize& data_size, void* user_data = nullptr)
void Map(const VkDeviceSize& size_to_map, const VkDeviceSize& offset_to_map_at, void** address_to_map_to) const
Maps the given size and offset of this allocation, and writes the mapped address to the specified pointer.
void Unmap() const noexcept
Unmaps the allocation - it is vital to call this when finished, as it may otherwise cause issues if left mapped.
auto Memory() const -> const VkDeviceMemory&
This handle to the underlying VkDeviceMemory object will be a shared handle, when this allocation is non-private.
auto IsPrivateAllocation() const -> bool noexcept
Returns true if this allocation is "private" - i.e, it is not part of a larger VkDeviceMemory block and instead received it's own unique VkDeviceMemory instance.

Function documentation

vpr::Allocation::Allocation()

If this is an allocation bound to a smaller region of a larger object, it is a block allocation.

Otherwise, it has it's own VkDeviceMemory object and is a "PRIVATE_ALLOCATION" type.

void vpr::Allocation::Update(MemoryBlock* new_parent_block, const VkDeviceSize& new_offset)

Changes parent memory block, and specifies a new offset for the memory.

Requires re-updating internal data, and is usually part of a defrag routine.

void vpr::Allocation::InitPrivate(const uint32_t& type_idx, VkDeviceMemory& dvc_memory, bool persistently_mapped, void* mapped_data, const VkDeviceSize& data_size, void* user_data = nullptr)

Parameters
type_idx
dvc_memory
persistently_mapped If set, this object will be considered to be always mapped. This will remove any worries about mapping/unmapping the object.
mapped_data
data_size
user_data