mirror of
https://github.com/ToyB-Chan/minimal-heap.git
synced 2026-07-13 21:51:16 +02:00
comments
This commit is contained in:
@@ -166,8 +166,10 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size)
|
|||||||
targetSegment->OccupiedSize = size;
|
targetSegment->OccupiedSize = size;
|
||||||
targetSegment->Checksum = MIHP_GenerateHeapSegmentChecksum(heap, targetSegment);
|
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->LastSuccessfulAllocationSegment = currentSegment;
|
||||||
|
|
||||||
|
currentArea->NumOccupiedSegments++;
|
||||||
currentArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(heap, currentArea);
|
currentArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(heap, currentArea);
|
||||||
|
|
||||||
heap->Stats.NumTotalOccupiedSegments++;
|
heap->Stats.NumTotalOccupiedSegments++;
|
||||||
@@ -279,7 +281,7 @@ void* MIHP_Reallocate(MIHP_Heap* heap, void* ptr, size_t newSize)
|
|||||||
MIHP_HeapSegmentHeader* newSpittedSegment = NULL;
|
MIHP_HeapSegmentHeader* newSpittedSegment = NULL;
|
||||||
MIHP_SplitHeapSegment(heap, segment, newSplitSegmentSize, &newSpittedSegment);
|
MIHP_SplitHeapSegment(heap, segment, newSplitSegmentSize, &newSpittedSegment);
|
||||||
if (newSpittedSegment && newSpittedSegment->NextSegment)
|
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);
|
MIHP_UnlockHeap(heap);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define USE_MALLOC 1
|
#define USE_MALLOC 0
|
||||||
|
|
||||||
#define MIHP_ValidateHeap(x)
|
#define MIHP_ValidateHeap(x)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user