WIP: Removed internal header tracking for WorkspaceHeap. Modified Handles to track the alignment that the underlying memory was aligned to. Re-worked WorkspaceHeap to use lists rather than Stack

This commit is contained in:
Jim
2026-03-23 22:26:01 +00:00
parent c2150acb2c
commit f73c09add5
6 changed files with 215 additions and 138 deletions

View File

@@ -11,5 +11,10 @@ namespace UnmanagedMMU.Handles.Internal
/// Returns the <see cref="IUnmanagedMemoryOwner"/> that created owns this <see cref="IOwnedHandle"/>
/// </summary>
IUnmanagedMemoryOwner GetOwner();
/// <summary>
/// Returns the memory alignment for the <see cref="IOwnedHandle"/>
/// </summary>
nuint Alignment { get; }
}
}

View File

@@ -41,18 +41,25 @@ namespace UnmanagedMMU.Handles
/// </summary>
private bool _disposed;
/// <summary>
/// The alignment of the memory pointed to by <see cref="_ptr"/>
/// </summary>
private readonly nuint _alignment;
/// <summary>
/// Initializes a new <see cref="MemoryHandleBase{T}"/> instnace
/// </summary>
/// <param name="ptr">Pointer to the allocated unmanaged memory</param>
/// <param name="byteLength">The size of the unallocated memory block in bytes</param>
/// <param name="alignment">The alignment that the unmanged memory pointed to by <paramref name="ptr"/> </param>
/// <param name="owner">The <see cref="IUnmanagedMemoryOwner"/> that owns the <see cref="MemoryHandleBase{T}"/> handle being created</param>
protected MemoryHandleBase(void* ptr, nuint byteLength, IUnmanagedMemoryOwner owner)
protected MemoryHandleBase(void* ptr, nuint byteLength, nuint alignment, IUnmanagedMemoryOwner owner)
{
// Defensive check
Debug.Assert(ptr != null, message: "BUG CHECK: E_INVALID_MEMORY_HANDLE");
_ptr = ptr;
_bytelen = byteLength;
_alignment = alignment;
_owner = owner;
}
@@ -64,6 +71,14 @@ namespace UnmanagedMMU.Handles
get { return _ptr; }
}
/// <summary>
/// Returns the memory alignment for the <see cref="MemoryHandleBase{T}"/>
/// </summary>
public virtual nuint Alignment
{
get { return _alignment; }
}
/// <summary>
/// Gets the typed pointer to the unmanged memory block
/// </summary>

View File

@@ -5,7 +5,7 @@ namespace UnmanagedMMU.Handles
internal sealed unsafe class PersistentMemoryHandle<T> : MemoryHandleBase<T> where T : unmanaged
{
public PersistentMemoryHandle(void* ptr, nuint byteLength, IUnmanagedMemoryOwner owner) : base(ptr, byteLength, owner)
public PersistentMemoryHandle(void* ptr, nuint byteLength, nuint alignment, IUnmanagedMemoryOwner owner) : base(ptr, byteLength, alignment, owner)
{
}

View File

@@ -1,15 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnmanagedMMU.Allocators;
using UnmanagedMMU.Allocators;
namespace UnmanagedMMU.Handles
{
internal sealed unsafe class SegmentedMemoryHandle<T> : MemoryHandleBase<T> where T : unmanaged
{
public SegmentedMemoryHandle(void* ptr, nuint byteLength, IUnmanagedMemoryOwner owner) : base(ptr, byteLength, owner)
public SegmentedMemoryHandle(void* ptr, nuint byteLength, nuint alignment, IUnmanagedMemoryOwner owner) : base(ptr, byteLength, alignment, owner)
{
}