blob: d3822111a166b375225f235bb5132b66a08f4afb [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Direct3D 12 Memory Allocator: Virtual allocator</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Direct3D 12 Memory Allocator
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">D3D12 Memory Allocator</a></li> </ul>
</div>
</div><!-- top -->
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">Virtual allocator </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>As an extra feature, the core allocation algorithm of the library is exposed through a simple and convenient API of "virtual allocator". It doesn't allocate any real GPU memory. It just keeps track of used and free regions of a "virtual block". You can use it to allocate your own memory or other objects, even completely unrelated to D3D12. A common use case is sub-allocation of pieces of one large GPU buffer.</p>
<h1><a class="anchor" id="virtual_allocator_creating_virtual_block"></a>
Creating virtual block</h1>
<p>To use this functionality, there is no main "allocator" object. You don't need to have <a class="el" href="class_d3_d12_m_a_1_1_allocator.html" title="Represents main object of this library initialized for particular ID3D12Device.">D3D12MA::Allocator</a> object created. All you need to do is to create a separate <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html" title="Represents pure allocation algorithm and a data structure with allocations in some memory block,...">D3D12MA::VirtualBlock</a> object for each block of memory you want to be managed by the allocator:</p>
<ol type="1">
<li>Fill in <a class="el" href="struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_o_r___d_e_s_c.html" title="Parameters of created Allocator object. To be used with CreateAllocator().">D3D12MA::ALLOCATOR_DESC</a> structure.</li>
<li>Call <a class="el" href="namespace_d3_d12_m_a.html#aefde6264e7a88bebe8e193df343af317" title="Creates new D3D12MA::VirtualBlock object and returns it through ppVirtualBlock.">D3D12MA::CreateVirtualBlock</a>. Get new <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html" title="Represents pure allocation algorithm and a data structure with allocations in some memory block,...">D3D12MA::VirtualBlock</a> object.</li>
</ol>
<p>Example:</p>
<div class="fragment"><div class="line"><a class="code" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___b_l_o_c_k___d_e_s_c.html">D3D12MA::VIRTUAL_BLOCK_DESC</a> blockDesc = {};</div>
<div class="line">blockDesc.<a class="code" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___b_l_o_c_k___d_e_s_c.html#ac56491679f276a5a9956ed99bc4654e4">Size</a> = 1048576; <span class="comment">// 1 MB</span></div>
<div class="line"> </div>
<div class="line"><a class="code" href="class_d3_d12_m_a_1_1_virtual_block.html">D3D12MA::VirtualBlock</a> *block;</div>
<div class="line">HRESULT hr = <a class="code" href="namespace_d3_d12_m_a.html#aefde6264e7a88bebe8e193df343af317">CreateVirtualBlock</a>(&amp;blockDesc, &amp;block);</div>
<div class="ttc" id="aclass_d3_d12_m_a_1_1_virtual_block_html"><div class="ttname"><a href="class_d3_d12_m_a_1_1_virtual_block.html">D3D12MA::VirtualBlock</a></div><div class="ttdoc">Represents pure allocation algorithm and a data structure with allocations in some memory block,...</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:1547</div></div>
<div class="ttc" id="anamespace_d3_d12_m_a_html_aefde6264e7a88bebe8e193df343af317"><div class="ttname"><a href="namespace_d3_d12_m_a.html#aefde6264e7a88bebe8e193df343af317">D3D12MA::CreateVirtualBlock</a></div><div class="ttdeci">HRESULT CreateVirtualBlock(const VIRTUAL_BLOCK_DESC *pDesc, VirtualBlock **ppVirtualBlock)</div><div class="ttdoc">Creates new D3D12MA::VirtualBlock object and returns it through ppVirtualBlock.</div></div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___b_l_o_c_k___d_e_s_c_html"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___b_l_o_c_k___d_e_s_c.html">D3D12MA::VIRTUAL_BLOCK_DESC</a></div><div class="ttdoc">Parameters of created D3D12MA::VirtualBlock object to be passed to CreateVirtualBlock().</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:1489</div></div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___b_l_o_c_k___d_e_s_c_html_ac56491679f276a5a9956ed99bc4654e4"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___b_l_o_c_k___d_e_s_c.html#ac56491679f276a5a9956ed99bc4654e4">D3D12MA::VIRTUAL_BLOCK_DESC::Size</a></div><div class="ttdeci">UINT64 Size</div><div class="ttdoc">Total size of the block.</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:1495</div></div>
</div><!-- fragment --><h1><a class="anchor" id="virtual_allocator_making_virtual_allocations"></a>
Making virtual allocations</h1>
<p><a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html" title="Represents pure allocation algorithm and a data structure with allocations in some memory block,...">D3D12MA::VirtualBlock</a> object contains internal data structure that keeps track of free and occupied regions using the same code as the main D3D12 memory allocator. However, there is no "virtual allocation" object. When you request a new allocation, a <code>UINT64</code> number is returned. It is an offset inside the block where the allocation has been placed, but it also uniquely identifies the allocation within this block.</p>
<p>In order to make an allocation:</p>
<ol type="1">
<li>Fill in <a class="el" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html" title="Parameters of created virtual allocation to be passed to VirtualBlock::Allocate().">D3D12MA::VIRTUAL_ALLOCATION_DESC</a> structure.</li>
<li>Call <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#aa57575f1af18461012bde8c4b6f3c56c" title="Creates new allocation.">D3D12MA::VirtualBlock::Allocate</a>. Get new <code>UINT64 offset</code> that identifies the allocation.</li>
</ol>
<p>Example:</p>
<div class="fragment"><div class="line"><a class="code" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html">D3D12MA::VIRTUAL_ALLOCATION_DESC</a> allocDesc = {};</div>
<div class="line">allocDesc.<a class="code" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#a976b649e45abdd0769da0d79acde4bac">Size</a> = 4096; <span class="comment">// 4 KB</span></div>
<div class="line"> </div>
<div class="line">UINT64 allocOffset;</div>
<div class="line">hr = block-&gt;<a class="code" href="class_d3_d12_m_a_1_1_virtual_block.html#aa57575f1af18461012bde8c4b6f3c56c">Allocate</a>(&amp;allocDesc, &amp;allocOffset);</div>
<div class="line"><span class="keywordflow">if</span>(SUCCEEDED(hr))</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// Use the 4 KB of your memory starting at allocOffset.</span></div>
<div class="line">}</div>
<div class="line"><span class="keywordflow">else</span></div>
<div class="line">{</div>
<div class="line"> <span class="comment">// Allocation failed - no space for it could be found. Handle this error!</span></div>
<div class="line">}</div>
<div class="ttc" id="aclass_d3_d12_m_a_1_1_virtual_block_html_aa57575f1af18461012bde8c4b6f3c56c"><div class="ttname"><a href="class_d3_d12_m_a_1_1_virtual_block.html#aa57575f1af18461012bde8c4b6f3c56c">D3D12MA::VirtualBlock::Allocate</a></div><div class="ttdeci">HRESULT Allocate(const VIRTUAL_ALLOCATION_DESC *pDesc, UINT64 *pOffset)</div><div class="ttdoc">Creates new allocation.</div></div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c_html"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html">D3D12MA::VIRTUAL_ALLOCATION_DESC</a></div><div class="ttdoc">Parameters of created virtual allocation to be passed to VirtualBlock::Allocate().</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:1505</div></div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c_html_a976b649e45abdd0769da0d79acde4bac"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#a976b649e45abdd0769da0d79acde4bac">D3D12MA::VIRTUAL_ALLOCATION_DESC::Size</a></div><div class="ttdeci">UINT64 Size</div><div class="ttdoc">Size of the allocation.</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:1510</div></div>
</div><!-- fragment --><h1><a class="anchor" id="virtual_allocator_deallocation"></a>
Deallocation</h1>
<p>When no longer needed, an allocation can be freed by calling <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#a02dfae4c0856f22da885a332de7821fa" title="Frees the allocation at given offset.">D3D12MA::VirtualBlock::FreeAllocation</a>. You can only pass to this function the exact offset that was previously returned by <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#aa57575f1af18461012bde8c4b6f3c56c" title="Creates new allocation.">D3D12MA::VirtualBlock::Allocate</a> and not any other location within the memory.</p>
<p>When whole block is no longer needed, the block object can be released by calling <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#a24111ca907ad9efae25cf4858ff6b0b0" title="Destroys this object and frees it from memory.">D3D12MA::VirtualBlock::Release</a>. All allocations must be freed before the block is destroyed, which is checked internally by an assert. However, if you don't want to call <code>block-&gt;FreeAllocation</code> for each allocation, you can use <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#ae22b18c0b7c31b44c1d740f886369189" title="Frees all the allocations.">D3D12MA::VirtualBlock::Clear</a> to free them all at once - a feature not available in normal D3D12 memory allocator. Example:</p>
<div class="fragment"><div class="line">block-&gt;<a class="code" href="class_d3_d12_m_a_1_1_virtual_block.html#a02dfae4c0856f22da885a332de7821fa">FreeAllocation</a>(allocOffset);</div>
<div class="line">block-&gt;<a class="code" href="class_d3_d12_m_a_1_1_virtual_block.html#a24111ca907ad9efae25cf4858ff6b0b0">Release</a>();</div>
<div class="ttc" id="aclass_d3_d12_m_a_1_1_virtual_block_html_a02dfae4c0856f22da885a332de7821fa"><div class="ttname"><a href="class_d3_d12_m_a_1_1_virtual_block.html#a02dfae4c0856f22da885a332de7821fa">D3D12MA::VirtualBlock::FreeAllocation</a></div><div class="ttdeci">void FreeAllocation(UINT64 offset)</div><div class="ttdoc">Frees the allocation at given offset.</div></div>
<div class="ttc" id="aclass_d3_d12_m_a_1_1_virtual_block_html_a24111ca907ad9efae25cf4858ff6b0b0"><div class="ttname"><a href="class_d3_d12_m_a_1_1_virtual_block.html#a24111ca907ad9efae25cf4858ff6b0b0">D3D12MA::VirtualBlock::Release</a></div><div class="ttdeci">void Release()</div><div class="ttdoc">Destroys this object and frees it from memory.</div></div>
</div><!-- fragment --><h1><a class="anchor" id="virtual_allocator_allocation_parameters"></a>
Allocation parameters</h1>
<p>You can attach a custom pointer to each allocation by using <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#a0af4aec3d2efc913ee43b0725e8a0289" title="Changes custom pointer for an allocation at given offset to a new value.">D3D12MA::VirtualBlock::SetAllocationUserData</a>. Its default value is <code>NULL</code>. It can be used to store any data that needs to be associated with that allocation - e.g. an index, a handle, or a pointer to some larger data structure containing more information. Example:</p>
<div class="fragment"><div class="line"><span class="keyword">struct </span>CustomAllocData</div>
<div class="line">{</div>
<div class="line"> std::string m_AllocName;</div>
<div class="line">};</div>
<div class="line">CustomAllocData* allocData = <span class="keyword">new</span> CustomAllocData();</div>
<div class="line">allocData-&gt;m_AllocName = <span class="stringliteral">&quot;My allocation 1&quot;</span>;</div>
<div class="line">block-&gt;<a class="code" href="class_d3_d12_m_a_1_1_virtual_block.html#a0af4aec3d2efc913ee43b0725e8a0289">SetAllocationUserData</a>(allocOffset, allocData);</div>
<div class="ttc" id="aclass_d3_d12_m_a_1_1_virtual_block_html_a0af4aec3d2efc913ee43b0725e8a0289"><div class="ttname"><a href="class_d3_d12_m_a_1_1_virtual_block.html#a0af4aec3d2efc913ee43b0725e8a0289">D3D12MA::VirtualBlock::SetAllocationUserData</a></div><div class="ttdeci">void SetAllocationUserData(UINT64 offset, void *pUserData)</div><div class="ttdoc">Changes custom pointer for an allocation at given offset to a new value.</div></div>
</div><!-- fragment --><p>The pointer can later be fetched, along with allocation size, by passing the allocation offset to function <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#a287b8f0e455ffc7f302094671f922afb" title="Returns information about an allocation at given offset - its size and custom pointer.">D3D12MA::VirtualBlock::GetAllocationInfo</a> and inspecting returned structure <a class="el" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___i_n_f_o.html" title="Parameters of an existing virtual allocation, returned by VirtualBlock::GetAllocationInfo().">D3D12MA::VIRTUAL_ALLOCATION_INFO</a>. If you allocated a new object to be used as the custom pointer, don't forget to delete that object before freeing the allocation! Example:</p>
<div class="fragment"><div class="line">VIRTUAL_ALLOCATION_INFO allocInfo;</div>
<div class="line">block-&gt;<a class="code" href="class_d3_d12_m_a_1_1_virtual_block.html#a287b8f0e455ffc7f302094671f922afb">GetAllocationInfo</a>(allocOffset, &amp;allocInfo);</div>
<div class="line"><span class="keyword">delete</span> (CustomAllocData*)allocInfo.pUserData;</div>
<div class="line"> </div>
<div class="line">block-&gt;<a class="code" href="class_d3_d12_m_a_1_1_virtual_block.html#a02dfae4c0856f22da885a332de7821fa">FreeAllocation</a>(allocOffset);</div>
<div class="ttc" id="aclass_d3_d12_m_a_1_1_virtual_block_html_a287b8f0e455ffc7f302094671f922afb"><div class="ttname"><a href="class_d3_d12_m_a_1_1_virtual_block.html#a287b8f0e455ffc7f302094671f922afb">D3D12MA::VirtualBlock::GetAllocationInfo</a></div><div class="ttdeci">void GetAllocationInfo(UINT64 offset, VIRTUAL_ALLOCATION_INFO *pInfo) const</div><div class="ttdoc">Returns information about an allocation at given offset - its size and custom pointer.</div></div>
</div><!-- fragment --><h1><a class="anchor" id="virtual_allocator_alignment_and_units"></a>
Alignment and units</h1>
<p>It feels natural to express sizes and offsets in bytes. If an offset of an allocation needs to be aligned to a multiply of some number (e.g. 4 bytes), you can fill optional member <a class="el" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#aaa95e62f2f399339a09dcbb312a42de0" title="Required alignment of the allocation.">D3D12MA::VIRTUAL_ALLOCATION_DESC::Alignment</a> to request it. Example:</p>
<div class="fragment"><div class="line"><a class="code" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html">D3D12MA::VIRTUAL_ALLOCATION_DESC</a> allocDesc = {};</div>
<div class="line">allocDesc.<a class="code" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#a976b649e45abdd0769da0d79acde4bac">Size</a> = 4096; <span class="comment">// 4 KB</span></div>
<div class="line">allocDesc.<a class="code" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#aaa95e62f2f399339a09dcbb312a42de0">Alignment</a> = 4; <span class="comment">// Returned offset must be a multiply of 4 B</span></div>
<div class="line"> </div>
<div class="line">UINT64 allocOffset;</div>
<div class="line">hr = block-&gt;<a class="code" href="class_d3_d12_m_a_1_1_virtual_block.html#aa57575f1af18461012bde8c4b6f3c56c">Allocate</a>(&amp;allocDesc, &amp;allocOffset);</div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c_html_aaa95e62f2f399339a09dcbb312a42de0"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#aaa95e62f2f399339a09dcbb312a42de0">D3D12MA::VIRTUAL_ALLOCATION_DESC::Alignment</a></div><div class="ttdeci">UINT64 Alignment</div><div class="ttdoc">Required alignment of the allocation.</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:1515</div></div>
</div><!-- fragment --><p>Alignments of different allocations made from one block may vary. However, if all alignments and sizes are always multiply of some size e.g. 4 B or <code>sizeof(MyDataStruct)</code>, you can express all sizes, alignments, and offsets in multiples of that size instead of individual bytes. It might be more convenient, but you need to make sure to use this new unit consistently in all the places:</p>
<ul>
<li><a class="el" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___b_l_o_c_k___d_e_s_c.html#ac56491679f276a5a9956ed99bc4654e4" title="Total size of the block.">D3D12MA::VIRTUAL_BLOCK_DESC::Size</a></li>
<li><a class="el" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#a976b649e45abdd0769da0d79acde4bac" title="Size of the allocation.">D3D12MA::VIRTUAL_ALLOCATION_DESC::Size</a> and <a class="el" href="struct_d3_d12_m_a_1_1_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#aaa95e62f2f399339a09dcbb312a42de0" title="Required alignment of the allocation.">D3D12MA::VIRTUAL_ALLOCATION_DESC::Alignment</a></li>
<li>Using offset returned by <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#aa57575f1af18461012bde8c4b6f3c56c" title="Creates new allocation.">D3D12MA::VirtualBlock::Allocate</a></li>
</ul>
<h1><a class="anchor" id="virtual_allocator_statistics"></a>
Statistics</h1>
<p>You can obtain statistics of a virtual block using <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#a039ee8426818d0126cf7f44c1c658526" title="Retrieves statistics from the current state of the block.">D3D12MA::VirtualBlock::CalculateStats</a>. The function fills structure <a class="el" href="struct_d3_d12_m_a_1_1_stat_info.html" title="Calculated statistics of memory usage in entire allocator.">D3D12MA::StatInfo</a> - same as used by the normal D3D12 memory allocator. Example:</p>
<div class="fragment"><div class="line"><a class="code" href="struct_d3_d12_m_a_1_1_stat_info.html">D3D12MA::StatInfo</a> statInfo;</div>
<div class="line">block-&gt;<a class="code" href="class_d3_d12_m_a_1_1_virtual_block.html#a039ee8426818d0126cf7f44c1c658526">CalculateStats</a>(&amp;statInfo);</div>
<div class="line">printf(<span class="stringliteral">&quot;My virtual block has %llu bytes used by %u virtual allocations\n&quot;</span>,</div>
<div class="line"> statInfo.<a class="code" href="struct_d3_d12_m_a_1_1_stat_info.html#ac4f3379ea88025e4ccf5880fab2699f7">UsedBytes</a>, statInfo.<a class="code" href="struct_d3_d12_m_a_1_1_stat_info.html#a2f50de812e296b71594174ff67bbac6e">AllocationCount</a>);</div>
<div class="ttc" id="aclass_d3_d12_m_a_1_1_virtual_block_html_a039ee8426818d0126cf7f44c1c658526"><div class="ttname"><a href="class_d3_d12_m_a_1_1_virtual_block.html#a039ee8426818d0126cf7f44c1c658526">D3D12MA::VirtualBlock::CalculateStats</a></div><div class="ttdeci">void CalculateStats(StatInfo *pInfo) const</div><div class="ttdoc">Retrieves statistics from the current state of the block.</div></div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_stat_info_html"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_stat_info.html">D3D12MA::StatInfo</a></div><div class="ttdoc">Calculated statistics of memory usage in entire allocator.</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:1183</div></div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_stat_info_html_a2f50de812e296b71594174ff67bbac6e"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_stat_info.html#a2f50de812e296b71594174ff67bbac6e">D3D12MA::StatInfo::AllocationCount</a></div><div class="ttdeci">UINT AllocationCount</div><div class="ttdoc">Number of D3D12MA::Allocation objects allocated.</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:1187</div></div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_stat_info_html_ac4f3379ea88025e4ccf5880fab2699f7"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_stat_info.html#ac4f3379ea88025e4ccf5880fab2699f7">D3D12MA::StatInfo::UsedBytes</a></div><div class="ttdeci">UINT64 UsedBytes</div><div class="ttdoc">Total number of bytes occupied by all allocations.</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:1191</div></div>
</div><!-- fragment --><p>You can also request a full list of allocations and free regions as a string in JSON format by calling <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#a828a27070bfa762cae796d4c8f2ef703" title="Builds and returns statistics as a string in JSON format, including the list of allocations with thei...">D3D12MA::VirtualBlock::BuildStatsString</a>. Returned string must be later freed using <a class="el" href="class_d3_d12_m_a_1_1_virtual_block.html#a6f78ddaa7da194e239089e52093e68a9" title="Frees memory of a string returned from VirtualBlock::BuildStatsString.">D3D12MA::VirtualBlock::FreeStatsString</a>. The format of this string may differ from the one returned by the main D3D12 allocator, but it is similar.</p>
<h1><a class="anchor" id="virtual_allocator_additional_considerations"></a>
Additional considerations</h1>
<p>Note that the "virtual allocator" functionality is implemented on a level of individual memory blocks. Keeping track of a whole collection of blocks, allocating new ones when out of free space, deleting empty ones, and deciding which one to try first for a new allocation must be implemented by the user. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>