From 1037256a30a69bfb7942186b132b1e07e8382d27 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Wed, 10 Jul 2024 21:49:40 +0200 Subject: [PATCH] wip --- include/util/pool_allocator.hpp | 40 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/include/util/pool_allocator.hpp b/include/util/pool_allocator.hpp index 42bb58952..94e045e3d 100644 --- a/include/util/pool_allocator.hpp +++ b/include/util/pool_allocator.hpp @@ -63,16 +63,44 @@ template class PoolAllocator } } - PoolAllocator(const PoolAllocator &) {} + PoolAllocator(const PoolAllocator &) = delete; + PoolAllocator &operator=(const PoolAllocator &) = delete; - PoolAllocator &operator=(const PoolAllocator &){return *this;} + PoolAllocator(PoolAllocator &&other) noexcept + : free_lists_(std::move(other.free_lists_)), + blocks_(std::move(other.blocks_)), + current_block_ptr_(other.current_block_ptr_), + current_block_left_items_(other.current_block_left_items_), + total_allocated_(other.total_allocated_) + { + other.current_block_ptr_ = nullptr; + other.current_block_left_items_ = 0; + other.total_allocated_ = 0; + } - // You may also want to implement move semantics if needed - PoolAllocator(PoolAllocator &&) noexcept = default; - PoolAllocator &operator=(PoolAllocator &&) noexcept = default; + PoolAllocator &operator=(PoolAllocator &&other) noexcept + { + if (this != &other) + { + for (auto block : blocks_) + { + std::free(block); + } + free_lists_ = std::move(other.free_lists_); + blocks_ = std::move(other.blocks_); + current_block_ptr_ = other.current_block_ptr_; + current_block_left_items_ = other.current_block_left_items_; + total_allocated_ = other.total_allocated_; - private: + other.current_block_ptr_ = nullptr; + other.current_block_left_items_ = 0; + other.total_allocated_ = 0; + } + return *this; + } + +private: size_t get_next_power_of_two_exponent(size_t n) const { BOOST_ASSERT(n > 0);