Fixed abug in Stack and VirtualStack

This commit is contained in:
2026-04-03 00:45:39 +09:00
parent c0580d2b46
commit 7d621ae6b3
3 changed files with 3 additions and 19 deletions

View File

@@ -142,16 +142,8 @@ public unsafe partial struct Stack : IMemoryAllocator<Stack, Stack.CreationOpts>
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Free(void* ptr)
public readonly void Free(void* ptr)
{
if (ptr < _buffer && ptr >= _buffer + _size)
{
Debug.Fail("Attempting to free a pointer that is out of bounds of the current stack allocation.");
return; // Pointer is out of bounds, ignore
}
var offset = (nuint)((byte*)ptr - _buffer);
_offset = offset < _offset ? offset : _offset;
}
/// <summary>

View File

@@ -162,16 +162,8 @@ public unsafe struct VirtualStack : IMemoryAllocator<VirtualStack, VirtualStack.
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Free(void* ptr)
public readonly void Free(void* ptr)
{
if (ptr < _baseAddress && ptr >= _baseAddress + _committedSize)
{
Debug.Fail("Attempting to free a pointer that is out of bounds of the current stack allocation.");
return; // Pointer is out of bounds, ignore
}
var offset = (nuint)((byte*)ptr - _baseAddress);
_allocatedOffset = offset < _allocatedOffset ? offset : _allocatedOffset;
}
public void Dispose()