示例#1
0
        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
        }
示例#2
0
        public void Dispose()
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            DisposeSentinel.Dispose(ref m_Safety, ref m_DisposeSentinel);
#endif
            UnsafeListArray.Destroy(m_Array);
            m_Array = null;
        }
示例#3
0
        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
        }
示例#4
0
 public void Execute()
 {
     UnsafeListArray.Destroy(array);
 }