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:
35
Misaki.HighPerformance.LowLevel/Buffer/VirtualMemoryBlock.cs
Normal file
35
Misaki.HighPerformance.LowLevel/Buffer/VirtualMemoryBlock.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user