From c6432d1d4594ddcb9452085240afc49d1ac5e942 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Fri, 21 Sep 2018 16:44:16 +0200 Subject: [PATCH] Buddy allocation algorithm finished and documented! --- docs/gfx/Buddy_allocator.png | Bin 0 -> 3924 bytes docs/html/custom_memory_pools.html | 18 +- docs/html/debugging_memory_usage.html | 2 +- docs/html/index.html | 1 + docs/html/vk__mem__alloc_8h.html | 11 +- docs/html/vk__mem__alloc_8h_source.html | 260 ++++++++++++------------ src/Tests.cpp | 4 +- src/VmaUsage.h | 2 +- src/vk_mem_alloc.h | 56 ++++- 9 files changed, 211 insertions(+), 143 deletions(-) create mode 100644 docs/gfx/Buddy_allocator.png diff --git a/docs/gfx/Buddy_allocator.png b/docs/gfx/Buddy_allocator.png new file mode 100644 index 0000000000000000000000000000000000000000..507314d9e55d65678d439b11c760fe77fd328817 GIT binary patch literal 3924 zcma)8c|6qX_y3GLWuzE{uHD#*WGT5cSwdq(_MN6kVr*e7F~eoDq)aBtE*T1;l9a}B zk+~$3B}29%G+D-&iLvGT>5tz(-}`#q-}iaFKIfe0Ip=depXdFY^PH1zcOG?MpVU48 z01lun%^d&$Vgky2u)QF)^&Wc(GHApZv=a;*@vzHj;9MZg(metIglc|05Fu8gKe+gN zq=j3gW9XI0=u6>#Ky-BUv49Y4gzu#=zhj}{{sqfODbTtfZEormQ@AwY9p*KQr?IC- zKWaR`kW}L%0E;R_BzvEk5LL^3KVmY5_RsA*!A%kkN>;kCI*_sU&}$Q6Q!zNLyl4Nd zXI_Vc2U5m6^N7}Bg;0JmnJ2kTC%c?)%|3HOXS#c`JeCZa-MYz)H=lCW3h{lT^ILhN zI*W3}JLj%*8(u6fUsJAp^yrbhB6qGJln@vh$#ou#IOyQ*z0+85GWfghY1EL+A7Kv| z9IEPIM7HBmiLp1aoVnI_(ObB!b;d_3cc7p1Y$yE8lFZ@!ig;TV?T{0k4 z?NZa^hTG&a??oE!lrk@cGrxVai;ixrs#10KJQZ}ku$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@|3A7nZDwPvM&8x&j1z~YvW};@fk&cC^)ghk7th3K&@+ z?5SUu)0pQM5vN9I{|~qDzZSKBq(y!EY*YnyP3;|q_)39TX$qpHbV0cRJufZWZqfR5|IWXqMOSD|oDx6pJE zIe%{4NUXEuu-MzigYobgvJ3WP6jV6lEbt62cwo9tx!j6so0QrHH_3iz2TxULuDr45 zncYfPcC0ZnDU~c@!VAzbjl}t_EW6Ad2=Kqm&w4;%D;UE@k^uy4OQqpReXEqR-g%5v z;C;TO+rP>QuXrL4dD4c?0{+>v{Ns54 fyQ%qCgI!_%2}YMZsio;xD}%N;Z(e)mV$y#ARh&O6 literal 0 HcmV?d00001 diff --git a/docs/html/custom_memory_pools.html b/docs/html/custom_memory_pools.html index 89132d1..be4cce0 100644 --- a/docs/html/custom_memory_pools.html +++ b/docs/html/custom_memory_pools.html @@ -141,7 +141,23 @@ Ring buffer
Ring buffer with lost allocations
-

Ring buffer is available only in pools with one memory block - VmaPoolCreateInfo::maxBlockCount must be 1. Otherwise behavior is undefined.

+

Ring buffer is available only in pools with one memory block - VmaPoolCreateInfo::maxBlockCount must be 1. Otherwise behavior is undefined.

+

+Buddy allocation algorithm

+

There is another allocation algorithm that can be used with custom pools, called "buddy". Its internal data structure is based on a tree of blocks, each having size that is a power of two and a half of its parent's size. When you want to allocate memory of certain size, a free node in the tree is located. If it's too large, it is recursively split into two halves (called "buddies"). However, if requested allocation size is not a power of two, the size of a tree node is aligned up to the nearest power of two and the remaining space is wasted. When two buddy nodes become free, they are merged back into one larger node.

+
+Buddy allocator +
+

The advantage of buddy allocation algorithm over default algorithm is faster allocation and deallocation, as well as smaller external fragmentation. The disadvantage is more wasted space (internal fragmentation).

+

For more information, please read "Buddy memory allocation" on Wikipedia or other sources that describe this concept in general.

+

To use buddy allocation algorithm with a custom pool, add flag VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT to VmaPoolCreateInfo::flags while creating VmaPool object.

+

Several limitations apply to pools that use buddy algorithm:

+
    +
  • It is recommended to use VmaPoolCreateInfo::blockSize that is a power of two. Otherwise, only largest power of two smaller than the size is used for allocations. The remaining space always stays unused.
  • +
  • Margins and corruption detection don't work in such pools.
  • +
  • Lost allocations don't work in such pools. You can use them, but they never become lost. Support may be added in the future.
  • +
  • Defragmentation doesn't work with allocations made from such pool.
  • +