feat(memory): transition to AllocationHandle API

Replaced the deprecated Allocator API with the new AllocationHandle API across the codebase. Updated constructors, methods, and tests to use AllocationHandle for memory management. Marked Allocator-based methods as [Obsolete] and provided alternatives.

Added OwnershipTransferAnalyzer to detect ownership transfer issues and introduced OwnershipTransferAttribute for marking parameters. Enhanced DefensiveCopyAnalyzer with additional checks for readonly and ValueType instances.

Refactored internal memory management in AllocationManager and updated benchmarks, utilities, and documentation to reflect the changes.

BREAKING CHANGE: Deprecated Allocator API in favor of AllocationHandle. Updated constructors and methods to use AllocationHandle. Users must migrate to the new API.
This commit is contained in:
2026-04-12 17:50:12 +09:00
parent a0deadc363
commit 9c4faa107a
40 changed files with 260 additions and 85 deletions

View File

@@ -43,12 +43,12 @@ public static unsafe class UnsafeCollectionUtility
/// </summary>
/// <typeparam name="T">The type of elements in the array, which must be unmanaged.</typeparam>
/// <param name="source">The managed array to convert.</param>
/// <param name="allocator">The allocator to use for memory allocation of the UnsafeArray.</param>
/// <param name="allocationHandle">The allocation handle to use for memory allocation of the UnsafeArray.</param>
/// <returns>A new UnsafeArray containing a copy of the source array elements.</returns>
public static UnsafeArray<T> ToUnsafeArray<T>(this T[] source, Allocator allocator)
public static UnsafeArray<T> ToUnsafeArray<T>(this T[] source, AllocationHandle allocationHandle)
where T : unmanaged
{
var array = new UnsafeArray<T>(source.Length, allocator);
var array = new UnsafeArray<T>(source.Length, allocationHandle);
fixed (T* pSrc = source)
{
MemCpy(array.GetUnsafePtr(), pSrc, (uint)(source.Length * sizeof(T)));
@@ -62,12 +62,12 @@ public static unsafe class UnsafeCollectionUtility
/// </summary>
/// <typeparam name="T">The type of elements in the list, which must be unmanaged.</typeparam>
/// <param name="source">The managed List to convert.</param>
/// <param name="allocator">The allocator to use for memory allocation of the UnsafeList.</param>
/// <param name="allocationHandle">The allocation handle to use for memory allocation of the UnsafeList.</param>
/// <returns>A new UnsafeList containing a copy of the source list elements.</returns>
public static UnsafeList<T> ToUnsafeList<T>(this List<T> source, Allocator allocator)
public static UnsafeList<T> ToUnsafeList<T>(this List<T> source, AllocationHandle allocationHandle)
where T : unmanaged
{
var list = new UnsafeList<T>(source.Count, allocator);
var list = new UnsafeList<T>(source.Count, allocationHandle);
fixed (T* pSrc = CollectionsMarshal.AsSpan(source))
{
MemCpy(list.GetUnsafePtr(), pSrc, (uint)(source.Count * sizeof(T)));