<p>You can annotate allocations with your own information, e.g. for debugging purposes. To do that, fill <aclass="el"href="struct_vma_allocation_create_info.html#a8259e85c272683434f4abb4ddddffe19"title="Custom general-purpose pointer that will be stored in VmaAllocation, can be read as VmaAllocationInfo...">VmaAllocationCreateInfo::pUserData</a> field when creating an allocation. It's an opaque <code>void*</code> pointer. You can use it e.g. as a pointer, some handle, index, key, ordinal number or any other value that would associate the allocation with your custom metadata.</p>
<divclass="fragment"><divclass="line">VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };</div><divclass="line"><spanclass="comment">// Fill bufferInfo...</span></div><divclass="line"></div><divclass="line">MyBufferMetadata* pMetadata = CreateBufferMetadata();</div><divclass="line"></div><divclass="line"><aclass="code"href="struct_vma_allocation_create_info.html">VmaAllocationCreateInfo</a> allocCreateInfo = {};</div><divclass="line">allocCreateInfo.<aclass="code"href="struct_vma_allocation_create_info.html#accb8b06b1f677d858cb9af20705fa910">usage</a> = <aclass="code"href="vk__mem__alloc_8h.html#aa5846affa1e9da3800e3e78fae2305ccac6b5dc1432d88647aa4cd456246eadf7">VMA_MEMORY_USAGE_GPU_ONLY</a>;</div><divclass="line">allocCreateInfo.<aclass="code"href="struct_vma_allocation_create_info.html#a8259e85c272683434f4abb4ddddffe19">pUserData</a> = pMetadata;</div><divclass="line"></div><divclass="line">VkBuffer buffer;</div><divclass="line">VmaAllocation allocation;</div><divclass="line"><aclass="code"href="vk__mem__alloc_8h.html#ac72ee55598617e8eecca384e746bab51">vmaCreateBuffer</a>(allocator, &bufferInfo, &allocCreateInfo, &buffer, &allocation, <spanclass="keyword">nullptr</span>);</div></div><!-- fragment --><p>The pointer may be later retrieved as <aclass="el"href="struct_vma_allocation_info.html#adc507656149c04de7ed95d0042ba2a13"title="Custom general-purpose pointer that was passed as VmaAllocationCreateInfo::pUserData or set using vma...">VmaAllocationInfo::pUserData</a>:</p>
<divclass="fragment"><divclass="line"><aclass="code"href="struct_vma_allocation_info.html">VmaAllocationInfo</a> allocInfo;</div><divclass="line"><aclass="code"href="vk__mem__alloc_8h.html#a86dd08aba8633bfa4ad0df2e76481d8b">vmaGetAllocationInfo</a>(allocator, allocation, &allocInfo);</div><divclass="line">MyBufferMetadata* pMetadata = (MyBufferMetadata*)allocInfo.<aclass="code"href="struct_vma_allocation_info.html#adc507656149c04de7ed95d0042ba2a13">pUserData</a>;</div></div><!-- fragment --><p>It can also be changed using function <aclass="el"href="vk__mem__alloc_8h.html#af9147d31ffc11d62fc187bde283ed14f"title="Sets pUserData in given allocation to new value. ">vmaSetAllocationUserData()</a>.</p>
<p>Values of (non-zero) allocations' <code>pUserData</code> are printed in JSON report created by <aclass="el"href="vk__mem__alloc_8h.html#aa4fee7eb5253377599ef4fd38c93c2a0"title="Builds and returns statistics as string in JSON format. ">vmaBuildStatsString()</a>, in hexadecimal form.</p>
<p>There is alternative mode available where <code>pUserData</code> pointer is used to point to a null-terminated string, giving a name to the allocation. To use this mode, set <aclass="el"href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597aa6f24f821cd6a7c5e4a443f7bf59c520">VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT</a> flag in <aclass="el"href="struct_vma_allocation_create_info.html#add09658ac14fe290ace25470ddd6d41b"title="Use VmaAllocationCreateFlagBits enum. ">VmaAllocationCreateInfo::flags</a>. Then <code>pUserData</code> passed as <aclass="el"href="struct_vma_allocation_create_info.html#a8259e85c272683434f4abb4ddddffe19"title="Custom general-purpose pointer that will be stored in VmaAllocation, can be read as VmaAllocationInfo...">VmaAllocationCreateInfo::pUserData</a> or argument to <aclass="el"href="vk__mem__alloc_8h.html#af9147d31ffc11d62fc187bde283ed14f"title="Sets pUserData in given allocation to new value. ">vmaSetAllocationUserData()</a> must be either null or pointer to a null-terminated string. The library creates internal copy of the string, so the pointer you pass doesn't need to be valid for whole lifetime of the allocation. You can free it after the call.</p>
<divclass="fragment"><divclass="line">VkImageCreateInfo imageInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };</div><divclass="line"><spanclass="comment">// Fill imageInfo...</span></div><divclass="line"></div><divclass="line">std::string imageName = <spanclass="stringliteral">"Texture: "</span>;</div><divclass="line">imageName += fileName;</div><divclass="line"></div><divclass="line"><aclass="code"href="struct_vma_allocation_create_info.html">VmaAllocationCreateInfo</a> allocCreateInfo = {};</div><divclass="line">allocCreateInfo.<aclass="code"href="struct_vma_allocation_create_info.html#accb8b06b1f677d858cb9af20705fa910">usage</a> = <aclass="code"href="vk__mem__alloc_8h.html#aa5846affa1e9da3800e3e78fae2305ccac6b5dc1432d88647aa4cd456246eadf7">VMA_MEMORY_USAGE_GPU_ONLY</a>;</div><divclass="line">allocCreateInfo.<aclass="code"href="struct_vma_allocation_create_info.html#add09658ac14fe290ace25470ddd6d41b">flags</a> = <aclass="code"href="vk__mem__alloc_8h.html#ad9889c10c798b040d59c92f257cae597aa6f24f821cd6a7c5e4a443f7bf59c520">VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT</a>;</div><divclass="line">allocCreateInfo.<aclass="code"href="struct_vma_allocation_create_info.html#a8259e85c272683434f4abb4ddddffe19">pUserData</a> = imageName.c_str();</div><divclass="line"></div><divclass="line">VkImage image;</div><divclass="line">VmaAllocation allocation;</div><divclass="line"><aclass="code"href="vk__mem__alloc_8h.html#a02a94f25679275851a53e82eacbcfc73">vmaCreateImage</a>(allocator, &imageInfo, &allocCreateInfo, &image, &allocation, <spanclass="keyword">nullptr</span>);</div></div><!-- fragment --><p>The value of <code>pUserData</code> pointer of the allocation will be different than the one you passed when setting allocation's name - pointing to a buffer managed internally that holds copy of the string.</p>
<divclass="fragment"><divclass="line"><aclass="code"href="struct_vma_allocation_info.html">VmaAllocationInfo</a> allocInfo;</div><divclass="line"><aclass="code"href="vk__mem__alloc_8h.html#a86dd08aba8633bfa4ad0df2e76481d8b">vmaGetAllocationInfo</a>(allocator, allocation, &allocInfo);</div><divclass="line"><spanclass="keyword">const</span><spanclass="keywordtype">char</span>* imageName = (<spanclass="keyword">const</span><spanclass="keywordtype">char</span>*)allocInfo.<aclass="code"href="struct_vma_allocation_info.html#adc507656149c04de7ed95d0042ba2a13">pUserData</a>;</div><divclass="line">printf(<spanclass="stringliteral">"Image name: %s\n"</span>, imageName);</div></div><!-- fragment --><p>That string is also printed in JSON report created by <aclass="el"href="vk__mem__alloc_8h.html#aa4fee7eb5253377599ef4fd38c93c2a0"title="Builds and returns statistics as string in JSON format. ">vmaBuildStatsString()</a>. </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hrclass="footer"/><addressclass="footer"><small>
Generated by  <ahref="http://www.doxygen.org/index.html">