| 5146 | |
| 5147 | template<typename T> |
| 5148 | void VmaPoolAllocator<T>::Free(T* ptr) |
| 5149 | { |
| 5150 | // Search all memory blocks to find ptr. |
| 5151 | for (size_t i = m_ItemBlocks.size(); i--; ) |
| 5152 | { |
| 5153 | ItemBlock& block = m_ItemBlocks[i]; |
| 5154 | |
| 5155 | // Casting to union. |
| 5156 | Item* pItemPtr = VMA_NULL; |
| 5157 | memcpy(&pItemPtr, &ptr, sizeof(pItemPtr)); |
| 5158 | |
| 5159 | // Check if pItemPtr is in address range of this block. |
| 5160 | if ((pItemPtr >= block.pItems) && (pItemPtr < block.pItems + block.Capacity)) |
| 5161 | { |
| 5162 | ptr->~T(); // Explicit destructor call. |
| 5163 | const uint32_t index = static_cast<uint32_t>(pItemPtr - block.pItems); |
| 5164 | pItemPtr->NextFreeIndex = block.FirstFreeIndex; |
| 5165 | block.FirstFreeIndex = index; |
| 5166 | return; |
| 5167 | } |
| 5168 | } |
| 5169 | VMA_ASSERT(0 && "Pointer doesn't belong to this memory pool."); |
| 5170 | } |
| 5171 | |
| 5172 | template<typename T> |
| 5173 | typename VmaPoolAllocator<T>::ItemBlock& VmaPoolAllocator<T>::CreateNewBlock() |
no test coverage detected