feat(core)!: refactor safety/debug defines, remove FreeList in JobSchedular

Refactor to use MHP_ENABLE_SAFETY_CHECKS, MHP_ENABLE_STACKTRACE, and MHP_ENABLE_MIMALLOC for feature toggling. Remove FreeList allocator in JobSchedular and debug-layer code, simplifying memory management. Improve memory leak detection and reporting, update memory allocation API, and guard all safety/debug features with new defines. Update csproj files, README, and code samples to match new API and toggles. Fix and improve collection types for correct behavior with and without safety checks. The codebase is now more modular and easier to configure for different build environments.

BREAKING CHANGE: Old defines (ENABLE_SAFETY_CHECKS, ENABLE_DEBUG_LAYER, ENABLE_MIMALLOC) are replaced with MHP_* equivalents. FreeList allocator and related debug features are removed. Some APIs and behaviors have changed for safety/debug configuration.
This commit is contained in:
2026-03-30 15:21:09 +09:00
parent 8231d6df60
commit aae8e2826f
27 changed files with 310 additions and 573 deletions

View File

@@ -76,7 +76,7 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
private T* _buffer;
private int _count;
#if ENABLE_DEBUG_LAYER
#if MHP_ENABLE_SAFETY_CHECKS
private MemoryHandle _memoryHandle;
#endif
private AllocationHandle _allocationHandle;
@@ -108,7 +108,7 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
{
get
{
#if ENABLE_DEBUG_LAYER
#if MHP_ENABLE_SAFETY_CHECKS
if (_buffer != null)
{
if (_allocationHandle.IsValid != null)
@@ -167,17 +167,17 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
throw new InvalidOperationException("Target allocation handle does not support allocation.");
}
#if ENABLE_DEBUG_LAYER
#if MHP_ENABLE_SAFETY_CHECKS
MemoryHandle memHandle;
#endif
var buff = handle.Alloc(handle.State, (nuint)(count * sizeof(T)), AlignOf<T>(), allocationOption
#if ENABLE_DEBUG_LAYER
#if MHP_ENABLE_SAFETY_CHECKS
, &memHandle
#endif
);
_buffer = (T*)buff;
#if ENABLE_DEBUG_LAYER
#if MHP_ENABLE_SAFETY_CHECKS
_memoryHandle = memHandle;
#endif
_allocationHandle = handle;
@@ -213,7 +213,7 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Conditional("ENABLE_SAFETY_CHECKS")]
[Conditional("MHP_ENABLE_SAFETY_CHECKS")]
private readonly void ThrowIfNotCreated()
{
if (!IsCreated)
@@ -223,7 +223,7 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Conditional("ENABLE_SAFETY_CHECKS")]
[Conditional("MHP_ENABLE_SAFETY_CHECKS")]
private readonly void CheckIndexBounds(int index)
{
ThrowIfNotCreated();
@@ -258,16 +258,16 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
return;
}
#if ENABLE_DEBUG_LAYER
#if MHP_ENABLE_SAFETY_CHECKS
MemoryHandle memHandle = _memoryHandle;
#endif
var elemSize = SizeOf<T>();
_buffer = (T*)_allocationHandle.Realloc(_allocationHandle.State, _buffer, (nuint)Count * elemSize, (nuint)newSize * elemSize, AlignOf<T>(), option
#if ENABLE_DEBUG_LAYER
#if MHP_ENABLE_SAFETY_CHECKS
, &memHandle
#endif
);
#if ENABLE_DEBUG_LAYER
#if MHP_ENABLE_SAFETY_CHECKS
_memoryHandle = memHandle;
#endif
_count = newSize;
@@ -424,7 +424,7 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
if (_allocationHandle.Free != null)
{
_allocationHandle.Free(_allocationHandle.State, _buffer
#if ENABLE_DEBUG_LAYER
#if MHP_ENABLE_SAFETY_CHECKS
, _memoryHandle
#endif
);