Updated the SegmentedPool to allow for zeroing of allocations and for returning a pointer to allocated memory to allow for use in unsafe structs

This commit is contained in:
Jim
2025-11-24 20:50:25 +00:00
parent dfbdf905fe
commit e257f2d3f2
15 changed files with 2788 additions and 674 deletions

View File

@@ -1,9 +1,11 @@
namespace UnmanagedMMU.Allocators
using System.Runtime.InteropServices;
namespace UnmanagedMMU.Allocators
{
/// <summary>
/// Interface that defines an Unmanaged allocator
/// </summary>
internal unsafe interface IUnmanagedAllocator
public unsafe interface IUnmanagedAllocator
{
/// <summary>
/// Allocates an unmanaged memory block of the specified size.
@@ -14,10 +16,28 @@
/// </returns>
void* Alloc(nuint size);
/// <summary>
/// Allocates an unmanaged memory block of the specified size with the requested alignment
/// </summary>
/// <param name="size">The number of bytes to allocate.</param>
/// <param name="alignment">The alignment, in bytes, of the block to allocate. This must be a power of <c>2</c></param>
/// <returns></returns>
void* AllocAligned(nuint size, nuint alignment);
/// <summary>
/// Frees a previously allocated unmanaged memory block.
/// </summary>
/// <param name="ptr">A pointer to the beginning of the memory block to free.</param>
/// <remarks>This method should only be called on with pointers allocated with <see cref="Alloc"/>.</remarks>
void Free(void* ptr);
/// <summary>
/// Frees a previously allocated unmanaged aligned memory block
/// </summary>
/// <param name="ptr">A pointer to the beginning of the memory block to free.</param>
/// <param name="alignment">The alignment that the memory refered to by <paramref name="ptr"/> was aligned at (This parameter can be ignored if the underlying allocator does not need it)</param>
/// <remarks>This method should only be called on with pointers allocated with <see cref="AllocAligned"/>.</remarks>
void FreeAligned(void* ptr, nuint alignment = 0);
}
}