NativeListArray(int initialListCapacity, Allocator allocator, int disposeSentinelStackDepth) { var totalSize = UnsafeUtility.SizeOf <T>() * (long)initialListCapacity; #if ENABLE_UNITY_COLLECTIONS_CHECKS // Native allocation is only valid for Temp, Job and Persistent. if (allocator <= Allocator.None) { throw new ArgumentException("Allocator must be Temp, TempJob or Persistent", nameof(allocator)); } if (initialListCapacity < 0) { throw new ArgumentOutOfRangeException(nameof(initialListCapacity), "InitialListCapacity must be >= 0"); } CollectionHelper.CheckIsUnmanaged <T>(); if (totalSize > int.MaxValue) { throw new ArgumentOutOfRangeException(nameof(initialListCapacity), $"InitialListCapacity * sizeof(T) cannot exceed {int.MaxValue} bytes"); } DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, disposeSentinelStackDepth, allocator); #endif m_Array = UnsafeListArray.Create(allocator); m_Array->InitialListCapacity = initialListCapacity; #if ENABLE_UNITY_COLLECTIONS_CHECKS AtomicSafetyHandle.SetBumpSecondaryVersionOnScheduleWrite(m_Safety, true); #endif }
public void Dispose() { #if ENABLE_UNITY_COLLECTIONS_CHECKS DisposeSentinel.Dispose(ref m_Safety, ref m_DisposeSentinel); #endif UnsafeListArray.Destroy(m_Array); m_Array = null; }
NativeListArray(int initialListCapacity, Allocator allocator, int disposeSentinelStackDepth) { var totalSize = UnsafeUtility.SizeOf <T>() * (long)initialListCapacity; #if ENABLE_UNITY_COLLECTIONS_CHECKS // Native allocation is only valid for Temp, Job and Persistent. CheckAllocator(allocator); CheckArgPositive(initialListCapacity); //CollectionHelper.CheckIsUnmanaged<T>(); CheckArgInRange(totalSize, int.MaxValue); DisposeSentinel.Create(out m_Safety, out m_DisposeSentinel, disposeSentinelStackDepth, allocator); #endif m_Array = UnsafeListArray.Create(allocator); m_Array->InitialListCapacity = initialListCapacity; #if ENABLE_UNITY_COLLECTIONS_CHECKS AtomicSafetyHandle.SetBumpSecondaryVersionOnScheduleWrite(m_Safety, true); #endif }
public void Execute() { UnsafeListArray.Destroy(array); }