Add SparseSet Test
This commit is contained in:
@@ -261,7 +261,7 @@ public static unsafe class AllocationManager
|
||||
private static bool s_debugLayer;
|
||||
private static bool s_disposed;
|
||||
|
||||
private static AllocationHeader* s_liveHead;
|
||||
private static AllocationHeader* s_pLiveHead;
|
||||
private static SpinLock s_liveLock;
|
||||
|
||||
private readonly static ConcurrentSlotMap<IntPtr> s_allocations;
|
||||
@@ -289,6 +289,8 @@ public static unsafe class AllocationManager
|
||||
s_pArenaAllocator->Init(_DEFAULT_MEMORY_POOL_SIZE);
|
||||
s_pHeapAllocator->Init();
|
||||
s_pStackAllocator->Init();
|
||||
|
||||
s_pLiveHead = null;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -321,12 +323,12 @@ public static unsafe class AllocationManager
|
||||
{
|
||||
s_liveLock.Enter(ref taken);
|
||||
header->prev = null;
|
||||
header->next = s_liveHead;
|
||||
if (s_liveHead != null)
|
||||
header->next = s_pLiveHead;
|
||||
if (s_pLiveHead != null)
|
||||
{
|
||||
s_liveHead->prev = header;
|
||||
s_pLiveHead->prev = header;
|
||||
}
|
||||
s_liveHead = header;
|
||||
s_pLiveHead = header;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -353,7 +355,7 @@ public static unsafe class AllocationManager
|
||||
}
|
||||
else
|
||||
{
|
||||
s_liveHead = next;
|
||||
s_pLiveHead = next;
|
||||
}
|
||||
|
||||
if (next != null)
|
||||
@@ -638,10 +640,10 @@ public static unsafe class AllocationManager
|
||||
try
|
||||
{
|
||||
s_liveLock.Enter(ref taken);
|
||||
if (s_liveHead != null)
|
||||
if (s_pLiveHead != null)
|
||||
{
|
||||
snapshot.Capacity = 128;
|
||||
for (var p = s_liveHead; p != null; p = p->next)
|
||||
for (var p = s_pLiveHead; p != null; p = p->next)
|
||||
{
|
||||
var trace = (StackTrace)HeaderGetHandle(p).Target!;
|
||||
snapshot.Add(new AllocationInfo
|
||||
|
||||
@@ -80,6 +80,7 @@ public unsafe struct UnsafeArray<T> : IUnsafeCollection<T>
|
||||
private AllocationHandle _allocationHandle;
|
||||
|
||||
public readonly int Count => _count;
|
||||
public readonly int Length => _count;
|
||||
|
||||
public readonly ref T this[int index]
|
||||
{
|
||||
|
||||
@@ -54,7 +54,7 @@ public unsafe struct UnsafeSlotMap<T> : IUnsafeCollection<T>
|
||||
public Enumerator(UnsafeSlotMap<T>* collection)
|
||||
{
|
||||
_collection = collection;
|
||||
_currentIndex = -1;
|
||||
_currentIndex = 0;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -65,7 +65,7 @@ public unsafe struct UnsafeSlotMap<T> : IUnsafeCollection<T>
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_currentIndex = -1;
|
||||
_currentIndex = 0;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -302,11 +302,13 @@ public unsafe struct UnsafeSlotMap<T> : IUnsafeCollection<T>
|
||||
_validBits.ClearAll();
|
||||
|
||||
_count = 0;
|
||||
|
||||
Add(default, out _);
|
||||
}
|
||||
|
||||
public readonly void* GetUnsafePtr()
|
||||
{
|
||||
return _data.GetUnsafePtr();
|
||||
return (T*)_data.GetUnsafePtr() + 1;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -56,7 +56,7 @@ public unsafe struct UnsafeSparseSet<T> : IUnsafeCollection<T>
|
||||
public Enumerator(UnsafeSparseSet<T>* collection)
|
||||
{
|
||||
_collection = collection;
|
||||
_currentIndex = -1;
|
||||
_currentIndex = 0;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -67,10 +67,10 @@ public unsafe struct UnsafeSparseSet<T> : IUnsafeCollection<T>
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_currentIndex = -1;
|
||||
_currentIndex = 0;
|
||||
}
|
||||
|
||||
public readonly unsafe void Dispose()
|
||||
public readonly void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -345,6 +345,8 @@ public unsafe struct UnsafeSparseSet<T> : IUnsafeCollection<T>
|
||||
|
||||
_count = 0;
|
||||
_nextId = 0;
|
||||
|
||||
Add(default, out _);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -371,7 +373,7 @@ public unsafe struct UnsafeSparseSet<T> : IUnsafeCollection<T>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void* GetUnsafePtr()
|
||||
{
|
||||
return _dense.GetUnsafePtr();
|
||||
return (T*)_dense.GetUnsafePtr() + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user