Improve FreeList/TLSF allocators: alignment, GC, decommit

- FreeList: enforce min 16B alignment, use GCHandle for SharedState lifetime, switch to AllocZeroed, and use MemoryUtility for oversized allocs
- Add FreeList.CollectLocal() to flush thread-local caches
- TLSF: add decommitted flag, support front splitting for alignment, add Collect() to decommit large free blocks, use Munmap for cleanup
- Add VirtualMemoryBlock for virtual memory management
- Add tests for CollectLocal (FreeList) and Collect (TLSF)
- Update default allocator config and minor .csproj cleanup
This commit is contained in:
2026-05-07 23:25:04 +09:00
parent d2c165bbe5
commit 259ff36100
7 changed files with 376 additions and 79 deletions

View File

@@ -0,0 +1,35 @@
using Misaki.HighPerformance.LowLevel.Utilities;
using System;
using System.Collections.Generic;
using System.Text;
namespace Misaki.HighPerformance.LowLevel.Buffer;
public unsafe struct VirtualMemoryBlock : IDisposable
{
private byte* _baseAddress;
private nuint _size;
private nuint _committed;
public VirtualMemoryBlock(nuint size)
{
_baseAddress = (byte*)MemoryUtility.Mmap(null, size, VirtualAllocationFlags.Reserve);
_size = size;
_committed = 0;
}
public void Dispose()
{
if (_baseAddress == null)
{
return;
}
var addr = _baseAddress;
_baseAddress = null;
_size = 0;
_committed = 0;
MemoryUtility.Munmap(addr, _size);
}
}