Skip to content

Commit 1037256

Browse files
wip
1 parent f9358ed commit 1037256

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

include/util/pool_allocator.hpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,44 @@ template <typename T, size_t MinItemsInBlock = 1024> class PoolAllocator
6363
}
6464
}
6565

66-
PoolAllocator(const PoolAllocator &) {}
66+
PoolAllocator(const PoolAllocator &) = delete;
67+
PoolAllocator &operator=(const PoolAllocator &) = delete;
68+
69+
PoolAllocator(PoolAllocator &&other) noexcept
70+
: free_lists_(std::move(other.free_lists_)),
71+
blocks_(std::move(other.blocks_)),
72+
current_block_ptr_(other.current_block_ptr_),
73+
current_block_left_items_(other.current_block_left_items_),
74+
total_allocated_(other.total_allocated_)
75+
{
76+
other.current_block_ptr_ = nullptr;
77+
other.current_block_left_items_ = 0;
78+
other.total_allocated_ = 0;
79+
}
6780

68-
PoolAllocator &operator=(const PoolAllocator &){return *this;}
81+
PoolAllocator &operator=(PoolAllocator &&other) noexcept
82+
{
83+
if (this != &other)
84+
{
85+
for (auto block : blocks_)
86+
{
87+
std::free(block);
88+
}
6989

70-
// You may also want to implement move semantics if needed
71-
PoolAllocator(PoolAllocator &&) noexcept = default;
72-
PoolAllocator &operator=(PoolAllocator &&) noexcept = default;
90+
free_lists_ = std::move(other.free_lists_);
91+
blocks_ = std::move(other.blocks_);
92+
current_block_ptr_ = other.current_block_ptr_;
93+
current_block_left_items_ = other.current_block_left_items_;
94+
total_allocated_ = other.total_allocated_;
7395

96+
other.current_block_ptr_ = nullptr;
97+
other.current_block_left_items_ = 0;
98+
other.total_allocated_ = 0;
99+
}
100+
return *this;
101+
}
74102

75-
private:
103+
private:
76104
size_t get_next_power_of_two_exponent(size_t n) const
77105
{
78106
BOOST_ASSERT(n > 0);

0 commit comments

Comments
 (0)