diff --git a/minimal_heap.c b/minimal_heap.c index c80dff9..16f21c9 100644 --- a/minimal_heap.c +++ b/minimal_heap.c @@ -24,7 +24,7 @@ MIHP_HeapInfo* MIHP_CreateHeap(MIHP_HeapConfig config) heap->Config = config; heap->FirstArea = MIHP_CreateHeapMemoryArea(heap, config.MinimalMemoryAreaSize); - heap->LastAllocationArea = heap->FirstArea; + heap->LastSuccessfulAllocationArea = heap->FirstArea; if (heap->FirstArea == NULL) { MIHP_PlatformFreeMemory(heap, sizeof(MIHP_HeapInfo)); @@ -71,16 +71,16 @@ void* MIHP_Allocate(MIHP_HeapInfo* heap, size_t size) MIHP_LOCK_HEAP(&heap->HeapLock); - bool checkedLastAllocationArea = false; + bool triedLastAllocationArea = false; MIHP_HeapMemoryAreaHeader* nextArea = heap->FirstArea; while (nextArea) { MIHP_HeapMemoryAreaHeader* currentArea = NULL; - if (!checkedLastAllocationArea) + if (!triedLastAllocationArea) { - currentArea = heap->LastAllocationArea; - checkedLastAllocationArea = true; + currentArea = heap->LastSuccessfulAllocationArea; + triedLastAllocationArea = true; } else { @@ -122,7 +122,7 @@ void* MIHP_Allocate(MIHP_HeapInfo* heap, size_t size) heap->Stats.NumTotalOccupiedSegments++; heap->Stats.TotalOccupiedSize += targetSegment->OccupiedSize; - heap->LastAllocationArea = currentArea; + heap->LastSuccessfulAllocationArea = currentArea; MIHP_UNLOCK_HEAP(&heap->HeapLock); @@ -147,6 +147,7 @@ void* MIHP_Allocate(MIHP_HeapInfo* heap, size_t size) heap->FirstArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(heap->FirstArea); heap->FirstArea = newArea; + heap->LastSuccessfulAllocationArea = newArea; newArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(newArea); MIHP_UNLOCK_HEAP(&heap->HeapLock); diff --git a/minimal_heap_test.c b/minimal_heap_test.c index 52d76aa..1d798a4 100644 --- a/minimal_heap_test.c +++ b/minimal_heap_test.c @@ -31,7 +31,7 @@ int main() config.AllocationInitialValue = 0xbe; config.AllocationAlignment = 16; config.MinimalMemoryAreaSize = 4096 * 32; - config.MaximalMemoryAreaSize = 4096ull * 4096ull; + config.MaximalMemoryAreaSize = 4096ull * 4096ull * 4096ull; MIHP_HeapInfo* myHeap = MIHP_CreateHeap(config); for (int i = 0; i < NUM_ALLOCATIONS; i++)