This commit is contained in:
2026-06-10 03:47:24 +02:00
parent fa3fbbc68d
commit b68c56580e
2 changed files with 5 additions and 3 deletions

View File

@@ -166,8 +166,10 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
targetSegment->OccupiedSize = size;
targetSegment->Checksum = MIHP_GenerateHeapSegmentChecksum(heap, targetSegment);
currentArea->NumOccupiedSegments++;
// Set it to currentSegment as it may be a large segment we've split targetSegment of
currentArea->LastSuccessfulAllocationSegment = currentSegment;
currentArea->NumOccupiedSegments++;
currentArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(heap, currentArea);
heap->Stats.NumTotalOccupiedSegments++;
@@ -279,7 +281,7 @@ void* MIHP_Reallocate(MIHP_Heap* heap, void* ptr, size_t newSize)
MIHP_HeapSegmentHeader* newSpittedSegment = NULL;
MIHP_SplitHeapSegment(heap, segment, newSplitSegmentSize, &newSpittedSegment);
if (newSpittedSegment && newSpittedSegment->NextSegment)
MIHP_MergeHeapSegments(heap, newSpittedSegment, newSpittedSegment->NextSegment);
MIHP_MergeHeapSegments(heap, newSpittedSegment, newSpittedSegment->NextSegment); // Try directly merging with the adjacent segment
}
MIHP_UnlockHeap(heap);

View File

@@ -5,7 +5,7 @@
#include <time.h>
#include <stdio.h>
#define USE_MALLOC 1
#define USE_MALLOC 0
#define MIHP_ValidateHeap(x)