Skip to content

Commit

Permalink
Cache the block which most recently successfully allocated something
Browse files Browse the repository at this point in the history
Otherwise, once the most recently allocated block was full, all allocations would need to scan the whole collection of blocks to find free space, which could take a while if lots of blocks had already been allocated but contained free space due to things being freed.
  • Loading branch information
AnyOldName3 committed Sep 25, 2024
1 parent a2ceceb commit 62c46a9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vsg/core/IntrusiveAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,11 @@ void* IntrusiveAllocator::MemoryBlocks::allocate(std::size_t size)
if (block != memoryBlockWithSpace)
{
auto ptr = block->allocate(size);
if (ptr) return ptr;
if (ptr)
{
memoryBlockWithSpace = block;
return ptr;
}
}
}

Expand Down

0 comments on commit 62c46a9

Please sign in to comment.