Add TLSF allocator and refactor allocation API
- Introduced TLSF allocator with thread-safe wrapper and integrated into AllocationManager. - Extended AllocationManagerDesc for TLSF config; made properties settable. - Refactored AllocationHandle to encapsulate function pointers and state, replacing direct field access with methods. - Updated all memory-related structs to use new AllocationHandle API. - Added ReplaceIfZeros utility to MemoryUtility. - Improved IndexOfNullByte performance. - Minor fix in MemoryLeakException output order. - FreeList now uses a fixed 64KB refill budget. - Bumped version to 1.6.21; removed MHP_ENABLE_STACKTRACE from Debug. - Updated Program.cs to test TLSF allocator and manage allocation lifecycle.
This commit is contained in:
@@ -86,8 +86,8 @@ public unsafe struct TLSF : IMemoryAllocator<TLSF, TLSF.CreationOptions>
|
||||
private uint* _slBitmaps;
|
||||
private BlockHeader** _blocks;
|
||||
private MemoryChunk* _chunks;
|
||||
private nuint _alignment;
|
||||
private nuint _chunkSize;
|
||||
private readonly nuint _alignment;
|
||||
private readonly nuint _chunkSize;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static TLSF Create(in CreationOptions opts)
|
||||
@@ -141,10 +141,6 @@ public unsafe struct TLSF : IMemoryAllocator<TLSF, TLSF.CreationOptions>
|
||||
{
|
||||
var totalSize = size + (nuint)sizeof(MemoryChunk);
|
||||
var mem = (byte*)AlignedAlloc(totalSize, _alignment);
|
||||
if (mem == null)
|
||||
{
|
||||
throw new OutOfMemoryException("Failed to allocate MemoryChunk for TlsfAllocator.");
|
||||
}
|
||||
|
||||
MemoryChunk* chunk = (MemoryChunk*)mem;
|
||||
chunk->next = _chunks;
|
||||
|
||||
Reference in New Issue
Block a user