From 62c46a99b8d51832c0c7df07746facd10dbcc237 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Wed, 25 Sep 2024 17:00:09 +0100 Subject: [PATCH] Cache the block which most recently successfully allocated something 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. --- src/vsg/core/IntrusiveAllocator.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vsg/core/IntrusiveAllocator.cpp b/src/vsg/core/IntrusiveAllocator.cpp index 4fd06b1b5..24c3633f2 100644 --- a/src/vsg/core/IntrusiveAllocator.cpp +++ b/src/vsg/core/IntrusiveAllocator.cpp @@ -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; + } } }