1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

common/memory: let allocators own a memory block

This is useful when we sub-delegate management of a memory block
to another allocator.
This commit is contained in:
Daniel Krebs 2018-07-20 16:44:28 +02:00
parent 0cdc05c3d5
commit 375b6b5cd3

View file

@ -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; }