Skip to content
Open
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
12 changes: 6 additions & 6 deletions offsetAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace OffsetAllocator
{
m_freeStorage = 0;
m_usedBinsTop = 0;
m_freeOffset = m_maxAllocs - 1;
m_freeOffset = m_maxAllocs;

for (uint32 i = 0 ; i < NUM_TOP_BINS; i++)
m_usedBins[i] = 0;
Expand All @@ -181,13 +181,13 @@ namespace OffsetAllocator
if (m_nodes) delete[] m_nodes;
if (m_freeNodes) delete[] m_freeNodes;

m_nodes = new Node[m_maxAllocs];
m_freeNodes = new NodeIndex[m_maxAllocs];
m_nodes = new Node[m_maxAllocs+1];
m_freeNodes = new NodeIndex[m_maxAllocs+1];

// Freelist is a stack. Nodes in inverse order so that [0] pops first.
for (uint32 i = 0; i < m_maxAllocs; i++)
for (uint32 i = 0; i < m_maxAllocs+1; i++)
{
m_freeNodes[i] = m_maxAllocs - i - 1;
m_freeNodes[i] = m_maxAllocs - i;
}

// Start state: Whole storage as one big node
Expand All @@ -204,7 +204,7 @@ namespace OffsetAllocator
Allocation Allocator::allocate(uint32 size)
{
// Out of allocations?
if (m_freeOffset == 0)
if (m_freeOffset == Allocation::NO_SPACE)
{
return {.offset = Allocation::NO_SPACE, .metadata = Allocation::NO_SPACE};
}
Expand Down