Vulkan Memory Allocator
|
Interleaved allocations and deallocations of many objects of varying size can cause fragmentation, which can lead to a situation where the library is unable to find a continuous range of free memory for a new allocation despite there is enough free space, just scattered across many small free ranges between existing allocations.
To mitigate this problem, you can use vmaDefragment(). Given set of allocations, this function can move them to compact used memory, ensure more continuous free space and possibly also free some VkDeviceMemory
. It can work only on allocations made from memory type that is HOST_VISIBLE
. Allocations are modified to point to the new VkDeviceMemory
and offset. Data in this memory is also memmove
-ed to the new place. However, if you have images or buffers bound to these allocations (and you certainly do), you need to destroy, recreate, and bind them to the new place in memory.
For further details and example code, see documentation of function vmaDefragment().