Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add assignment move operator and delete copy #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions offsetAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions offsetAllocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down