| 1719 | |
| 1720 | template<typename T> template<typename... Types> |
| 1721 | T* PoolAllocator<T>::Alloc(Types... args) |
| 1722 | { |
| 1723 | for(size_t i = m_ItemBlocks.size(); i--; ) |
| 1724 | { |
| 1725 | ItemBlock& block = m_ItemBlocks[i]; |
| 1726 | // This block has some free items: Use first one. |
| 1727 | if(block.FirstFreeIndex != UINT32_MAX) |
| 1728 | { |
| 1729 | Item* const pItem = &block.pItems[block.FirstFreeIndex]; |
| 1730 | block.FirstFreeIndex = pItem->NextFreeIndex; |
| 1731 | T* result = (T*)&pItem->Value; |
| 1732 | new(result)T(std::forward<Types>(args)...); // Explicit constructor call. |
| 1733 | return result; |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | // No block has free item: Create new one and use it. |
| 1738 | ItemBlock& newBlock = CreateNewBlock(); |
| 1739 | Item* const pItem = &newBlock.pItems[0]; |
| 1740 | newBlock.FirstFreeIndex = pItem->NextFreeIndex; |
| 1741 | T* result = (T*)pItem->Value; |
| 1742 | new(result)T(std::forward<Types>(args)...); // Explicit constructor call. |
| 1743 | return result; |
| 1744 | } |
| 1745 | |
| 1746 | template<typename T> |
| 1747 | void PoolAllocator<T>::Free(T* ptr) |
no test coverage detected