feat(buffer): improve Free safety and refactor tests
Stack and VirtualStack Free methods now check pointer bounds and update offsets only when appropriate, improving safety. Program.cs refactored to use MemoryPool with VirtualStack and new test methods. Assembly version bumped to 1.6.7.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Misaki.HighPerformance.LowLevel.Buffer;
|
||||
@@ -141,8 +142,16 @@ public unsafe partial struct Stack : IMemoryAllocator<Stack, Stack.CreationOpts>
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void Free(void* ptr)
|
||||
public 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>
|
||||
|
||||
Reference in New Issue
Block a user