Vulkan Memory Allocator
|
Vulkan Memory Allocator comes in form of a "stb-style" single header file. You don't need to build it as a separate library project. You can add this file directly to your project and submit it to code repository next to your other source files.
"Single header" doesn't mean that everything is contained in C/C++ declarations, like it tends to be in case of inline functions or C++ templates. It means that implementation is bundled with interface in a single file and needs to be extracted using preprocessor macro. If you don't do it properly, you will get linker errors.
To do it properly:
It may be a good idea to create dedicated CPP file just for this purpose.
Note on language: This library is written in C++, but has C-compatible interface. Thus you can include and use vk_mem_alloc.h in C or C++ code, but full implementation with VMA_IMPLEMENTATION
macro must be compiled as C++, NOT as C.
Please note that this library includes header <vulkan/vulkan.h>
, which in turn includes <windows.h>
on Windows. If you need some specific macros defined before including these headers (like WIN32_LEAN_AND_MEAN
or WINVER
for Windows, VK_USE_PLATFORM_WIN32_KHR
for Vulkan), you must define them before every #include
of this library.
At program startup:
VkPhysicalDevice
, VkDevice
and VkInstance
object.When you want to create a buffer or image:
VkBufferCreateInfo
/ VkImageCreateInfo
structure.VkBuffer
/VkImage
with memory already allocated and bound to it.Don't forget to destroy your objects when no longer needed: