diff --git a/offsetAllocator.cpp b/offsetAllocator.cpp index a51f9db..f8cc6e6 100644 --- a/offsetAllocator.cpp +++ b/offsetAllocator.cpp @@ -166,6 +166,25 @@ namespace OffsetAllocator other.m_usedBinsTop = 0; } + void Allocator::operator=(Allocator &&other) { + m_size = other.m_size; + m_maxAllocs = other.m_maxAllocs; + m_freeStorage = other.m_freeStorage; + m_usedBinsTop = other.m_usedBinsTop; + m_nodes = other.m_nodes; + m_freeNodes = other.m_freeNodes; + m_freeOffset = other.m_freeOffset; + + memcpy(m_usedBins, other.m_usedBins, sizeof(uint8) * NUM_TOP_BINS); + memcpy(m_binIndices, other.m_binIndices, sizeof(NodeIndex) * NUM_LEAF_BINS); + + other.m_nodes = nullptr; + other.m_freeNodes = nullptr; + other.m_freeOffset = 0; + other.m_maxAllocs = 0; + other.m_usedBinsTop = 0; + } + void Allocator::reset() { m_freeStorage = 0; diff --git a/offsetAllocator.hpp b/offsetAllocator.hpp index 155e21d..4c05fbb 100644 --- a/offsetAllocator.hpp +++ b/offsetAllocator.hpp @@ -53,9 +53,13 @@ namespace OffsetAllocator public: Allocator(uint32 size, uint32 maxAllocs = 128 * 1024); Allocator(Allocator &&other); + Allocator(const Allocator &other) = delete; ~Allocator(); void reset(); + void operator=(const Allocator &other) = delete; + void operator=(Allocator &&other); + Allocation allocate(uint32 size); void free(Allocation allocation);