feat(memory): improve oversized alloc handling & cleanup
Enhanced FreeList to handle oversized allocations by bypassing chunk management and allocating directly from the OS, with proper header assignment and immediate release on free. Updated IUnsafeCollection<T> documentation, removed unnecessary array clearing in Clear() methods, refined UnsafeSlotMap initialization logic, and removed redundant default element addition. Bumped assembly version to 1.5.1.
This commit is contained in:
@@ -540,10 +540,15 @@ public unsafe struct FreeList : IDisposable
|
||||
ptr = TryPopFromBucket(cache, cacheIndex, bucketIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr == null)
|
||||
else
|
||||
{
|
||||
ptr = AllocateFromChunk(cacheIndex, totalSize, alignment);
|
||||
// Oversized block: Bypass chunk linking entirely and go straight to the OS
|
||||
ptr = AlignedAlloc(totalSize, alignment);
|
||||
if (ptr != null)
|
||||
{
|
||||
// Pass null for ownerChunk so 'Free' knows this is a standalone allocation
|
||||
AssignBlockHeader((BlockHeader*)ptr, null, totalSize, cacheIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr == null)
|
||||
@@ -604,10 +609,10 @@ public unsafe struct FreeList : IDisposable
|
||||
|
||||
if (bucketIndex < 0)
|
||||
{
|
||||
header->ownerChunk = null;
|
||||
header->blockSize = 0;
|
||||
// This is an oversized allocation. It doesn't belong to a bucket or a chunk.
|
||||
// Erase the magic number for safety and instantly yield it back to the OS.
|
||||
header->magicNumber = 0;
|
||||
header->ownerCacheIndex = 0;
|
||||
AlignedFree(blockStartPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user