Commit 2ef40409 authored by Daniel Krebs's avatar Daniel Krebs
Browse files

common/memory: let allocators own a memory block

This is useful when we sub-delegate management of a memory block
to another allocator.
parent 1bb92b5f
......@@ -123,6 +123,12 @@ public:
};
}
BaseAllocator(std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn> mem) :
BaseAllocator(mem->getAddrSpaceId())
{
memoryBlock = std::move(mem);
}
virtual std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
allocateBlock(size_t size) = 0;
......@@ -174,6 +180,9 @@ protected:
MemoryBlock::deallocator_fn free;
SpdLogger logger;
// optional, if allocator should own the memory block
std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn> memoryBlock;
private:
MemoryManager::AddressSpaceId memoryAddrSpaceId;
DerivedAllocator* derivedAlloc;
......@@ -195,6 +204,12 @@ public:
size_t memorySize,
size_t internalOffset = 0);
LinearAllocator(std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn> mem) :
LinearAllocator(mem->getAddrSpaceId(), mem->getSize())
{
memoryBlock = std::move(mem);
}
size_t getAvailableMemory() const
{ return memorySize - nextFreeAddress; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment