26 #include "MemoryAllocator.h" 27 #include "FixedBlockMemoryAllocator.h" 28 #include "DebugUtilities.h" 35 class AdaptiveFixedBlockAllocator :
public IMemoryAllocator
38 AdaptiveFixedBlockAllocator(IMemoryAllocator &RawMemAllocator, Uint32 NumBlocksPerAllocation) :
39 m_RawMemAllocator(RawMemAllocator),
40 m_pFixedBlockAllocator(nullptr, STDDeleterRawMem<FixedBlockMemoryAllocator>(RawMemAllocator)),
41 m_NumBlocksPerAllocation(NumBlocksPerAllocation)
47 virtual void* Allocate(
size_t Size,
const Char* dbgDescription,
const char* dbgFileName,
const Int32 dbgLineNumber)
override final 49 if (m_NumBlocksPerAllocation > 1)
51 if( !m_pFixedBlockAllocator )
54 auto *pRawMem = m_RawMemAllocator.Allocate(
sizeof(FixedBlockMemoryAllocator),
"Memory for FixedBlockMemoryAllocator", __FILE__, __LINE__);
55 m_pFixedBlockAllocator.reset(
new(pRawMem) FixedBlockMemoryAllocator(m_RawMemAllocator, Size, m_NumBlocksPerAllocation) );
58 return m_pFixedBlockAllocator->Allocate(Size, dbgDescription, dbgFileName, dbgLineNumber);
63 return m_RawMemAllocator.Allocate(Size, dbgDescription, dbgFileName, dbgLineNumber);
68 virtual void Free(
void *Ptr)
override final 70 if (m_NumBlocksPerAllocation > 1)
72 VERIFY_EXPR(m_pFixedBlockAllocator);
73 m_pFixedBlockAllocator->Free(Ptr);
77 VERIFY_EXPR(!m_pFixedBlockAllocator);
78 m_RawMemAllocator.Free(Ptr);
83 IMemoryAllocator &m_RawMemAllocator;
84 Uint32 m_NumBlocksPerAllocation = 0;
85 std::unique_ptr<FixedBlockMemoryAllocator, STDDeleterRawMem<FixedBlockMemoryAllocator> > m_pFixedBlockAllocator;
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34