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:
@@ -3,14 +3,36 @@
|
||||
namespace UnmanagedMMU.Allocators
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class around <see cref="NativeMemory.Alloc(nuint)"/> and <see cref="NativeMemory.Free(void*)"/>.
|
||||
/// Wrapper class around <see cref="NativeMemory.AlignedAlloc(nuint, nuint)"/> and <see cref="NativeMemory.AlignedFree(void*)"/>.
|
||||
/// </summary>
|
||||
internal sealed unsafe class DefaultUnmanagedAllocator : IUnmanagedAllocator
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void* Alloc(nuint size) => NativeMemory.Alloc(size);
|
||||
public void* Alloc(nuint size)
|
||||
{
|
||||
return NativeMemory.AlignedAlloc(size, 16);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Free(void* ptr) => NativeMemory.Free(ptr);
|
||||
public void* AllocAligned(nuint size, nuint alignment)
|
||||
{
|
||||
if (!((alignment & (alignment - 1)) == 0 && alignment > 0))
|
||||
{
|
||||
throw new ArgumentException("Alignment must be a power of 2.", nameof(alignment));
|
||||
}
|
||||
return NativeMemory.AlignedAlloc(size, alignment);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Free(void* ptr)
|
||||
{
|
||||
NativeMemory.Free(ptr);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void FreeAligned(void* ptr, nuint alignment = 0)
|
||||
{
|
||||
NativeMemory.AlignedFree(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user