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:
@@ -9,8 +9,8 @@ public class TestAllocationManager
|
||||
[TestMethod]
|
||||
public void PersistentAllocationTest()
|
||||
{
|
||||
var ptr1 = new MemoryBlock(1024, 8, Allocator.Persistent);
|
||||
var ptr2 = new MemoryBlock(2048, 8, Allocator.Persistent);
|
||||
var ptr1 = new MemoryBlock(1024, 8, AllocationHandle.Persistent);
|
||||
var ptr2 = new MemoryBlock(2048, 8, AllocationHandle.Persistent);
|
||||
|
||||
Assert.IsTrue(ptr1.IsCreated);
|
||||
Assert.IsTrue(ptr2.IsCreated);
|
||||
@@ -25,8 +25,8 @@ public class TestAllocationManager
|
||||
[TestMethod]
|
||||
public void TempAllocationTest()
|
||||
{
|
||||
var ptr1 = new MemoryBlock(1024, 8, Allocator.Temp);
|
||||
var ptr2 = new MemoryBlock(2048, 8, Allocator.Temp);
|
||||
var ptr1 = new MemoryBlock(1024, 8, AllocationHandle.Temp);
|
||||
var ptr2 = new MemoryBlock(2048, 8, AllocationHandle.Temp);
|
||||
|
||||
Assert.IsTrue(ptr1.IsCreated);
|
||||
Assert.IsTrue(ptr2.IsCreated);
|
||||
@@ -41,8 +41,8 @@ public class TestAllocationManager
|
||||
[TestMethod]
|
||||
public void FreeListAllocationTest()
|
||||
{
|
||||
var ptr1 = new MemoryBlock(1024, 8, Allocator.FreeList);
|
||||
var ptr2 = new MemoryBlock(2048, 8, Allocator.FreeList);
|
||||
var ptr1 = new MemoryBlock(1024, 8, AllocationHandle.FreeList);
|
||||
var ptr2 = new MemoryBlock(2048, 8, AllocationHandle.FreeList);
|
||||
|
||||
Assert.IsTrue(ptr1.IsCreated);
|
||||
Assert.IsTrue(ptr2.IsCreated);
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TestUnsafeArray
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_arr = new UnsafeArray<int>(16, Allocator.Persistent);
|
||||
_arr = new UnsafeArray<int>(16, AllocationHandle.Persistent);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -12,8 +12,8 @@ public class TestUnsafeBitSet
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_set1 = new UnsafeBitSet(16, Allocator.Persistent, AllocationOption.Clear);
|
||||
_set2 = new UnsafeBitSet(16, Allocator.Persistent, AllocationOption.Clear);
|
||||
_set1 = new UnsafeBitSet(16, AllocationHandle.Persistent, AllocationOption.Clear);
|
||||
_set2 = new UnsafeBitSet(16, AllocationHandle.Persistent, AllocationOption.Clear);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -15,7 +15,7 @@ public class TestUnsafeChunkedQueue
|
||||
[TestMethod]
|
||||
public void BasicEnqueueDequeueTest()
|
||||
{
|
||||
using var queue = new UnsafeChunkedQueue<int>(32, Allocator.Persistent);
|
||||
using var queue = new UnsafeChunkedQueue<int>(32, AllocationHandle.Persistent);
|
||||
|
||||
Assert.IsTrue(queue.IsCreated);
|
||||
|
||||
@@ -35,7 +35,7 @@ public class TestUnsafeChunkedQueue
|
||||
public void ChunkExpansionTest()
|
||||
{
|
||||
// Force chunk expansions by enqueuing more than the chunk capacity
|
||||
using var queue = new UnsafeChunkedQueue<int>(16, Allocator.Persistent);
|
||||
using var queue = new UnsafeChunkedQueue<int>(16, AllocationHandle.Persistent);
|
||||
|
||||
var totalItems = 100;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class TestUnsafeChunkedQueue
|
||||
public void ConcurrentEnqueueDequeueTest()
|
||||
{
|
||||
// Multi-threaded stress test to verify lock-free safety and chunk caching
|
||||
using var queue = new UnsafeChunkedQueue<int>(64, Allocator.Persistent);
|
||||
using var queue = new UnsafeChunkedQueue<int>(64, AllocationHandle.Persistent);
|
||||
var totalElements = 100_000;
|
||||
|
||||
var enqueueTask = Task.Run(() =>
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TestUnsafeHashMap
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_map = new UnsafeHashMap<int, int>(4, Allocator.Persistent);
|
||||
_map = new UnsafeHashMap<int, int>(4, AllocationHandle.Persistent);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TestUnsafeHashSet
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_set = new UnsafeHashSet<int>(4, Allocator.Persistent);
|
||||
_set = new UnsafeHashSet<int>(4, AllocationHandle.Persistent);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TestUnsafeList
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_list = new UnsafeList<int>(4, Allocator.Persistent);
|
||||
_list = new UnsafeList<int>(4, AllocationHandle.Persistent);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TestUnsafeMultiHashMap
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_multiHashMap = new UnsafeMultiHashMap<int, int>(4, Allocator.Persistent);
|
||||
_multiHashMap = new UnsafeMultiHashMap<int, int>(4, AllocationHandle.Persistent);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -10,7 +10,7 @@ public class TestUnsafeQueue
|
||||
[TestInitialize]
|
||||
public void Setup()
|
||||
{
|
||||
_queue = new UnsafeQueue<int>(4, LowLevel.Buffer.Allocator.Persistent);
|
||||
_queue = new UnsafeQueue<int>(4, LowLevel.Buffer.AllocationHandle.Persistent);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TestUnsafeSlotMap
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_slotMap = new UnsafeSlotMap<int>(16, Allocator.Persistent);
|
||||
_slotMap = new UnsafeSlotMap<int>(16, AllocationHandle.Persistent);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TestUnsafeSparseSet
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_sparseSet = new UnsafeSparseSet<int>(16, Allocator.Persistent);
|
||||
_sparseSet = new UnsafeSparseSet<int>(16, AllocationHandle.Persistent);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TestUnsafeStack
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
_stack = new UnsafeStack<int>(16, Allocator.Persistent);
|
||||
_stack = new UnsafeStack<int>(16, AllocationHandle.Persistent);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
||||
@@ -171,7 +171,7 @@ public unsafe class TestJobSystem
|
||||
{
|
||||
const int arraySize = 10000;
|
||||
|
||||
using var array = new UnsafeArray<float>(arraySize, Allocator.Persistent);
|
||||
using var array = new UnsafeArray<float>(arraySize, AllocationHandle.Persistent);
|
||||
|
||||
for (var i = 0; i < arraySize; i++)
|
||||
{
|
||||
@@ -296,17 +296,17 @@ public unsafe class TestJobSystem
|
||||
[TestMethod]
|
||||
public void DynamicDispatch()
|
||||
{
|
||||
using var arr = new UnsafeArray<UnsafeArray<int>>(256, Allocator.Persistent);
|
||||
using var arr = new UnsafeArray<UnsafeArray<int>>(256, AllocationHandle.Persistent);
|
||||
for (var i = 0; i < arr.Length; i++)
|
||||
{
|
||||
arr[i] = new UnsafeArray<int>(256, Allocator.Persistent);
|
||||
arr[i] = new UnsafeArray<int>(256, AllocationHandle.Persistent);
|
||||
for (var j = 0; j < arr[i].Length; j++)
|
||||
{
|
||||
arr[i][j] = j;
|
||||
}
|
||||
}
|
||||
|
||||
using var handles = new UnsafeList<JobHandle>(arr.Length, Allocator.Persistent);
|
||||
using var handles = new UnsafeList<JobHandle>(arr.Length, AllocationHandle.Persistent);
|
||||
|
||||
var job = new JobDispatchingJob
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Misaki.HighPerformance.LowLevel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
Reference in New Issue
Block a user