MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / Alloc

Method Alloc

modules/engine/graphics/src/d3d12/D3D12MemAlloc.cpp:1721–1744  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1719
1720template<typename T> template<typename... Types>
1721T* 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
1746template<typename T>
1747void PoolAllocator<T>::Free(T* ptr)

Callers 7

PushBackMethod · 0.45
PushFrontMethod · 0.45
InsertBeforeMethod · 0.45
InsertAfterMethod · 0.45
AllocateMethod · 0.45
InitMethod · 0.45
NormalBlockClass · 0.45

Calls 11

MarkRangeAsUsedMethod · 0.80
GetSizeFunction · 0.70
sizeMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45
backMethod · 0.45
IsFreeMethod · 0.45
MarkTakenMethod · 0.45
MarkFreeMethod · 0.45

Tested by

no test coverage detected