private static void WriteNullReference(out DisposeSentinel reference) { reference = null; }
/// <summary> /// Create an empty hash set with a given capacity /// </summary> /// /// <param name="capacity"> /// Capacity of the hash set. If less than four, four is used. /// </param> /// /// <param name="allocator"> /// Allocator to allocate unmanaged memory with. Must be valid. /// </param> public NativeHashSet(int capacity, Allocator allocator) { // Require a valid allocator if (allocator <= Allocator.None) { throw new ArgumentException( "Allocator must be Temp, TempJob or Persistent", "allocator"); } RequireBlittable(); // Insist on a minimum capacity if (capacity < 4) { capacity = 4; } m_Allocator = allocator; // Allocate the state NativeHashSetState *state = (NativeHashSetState *)UnsafeUtility.Malloc( sizeof(NativeHashSetState), UnsafeUtility.AlignOf <NativeHashSetState>(), allocator); state->ItemCapacity = capacity; // To reduce collisions, use twice as many buckets int bucketLength = capacity * 2; bucketLength = NextHigherPowerOfTwo(bucketLength); state->BucketCapacityMask = bucketLength - 1; // Allocate state arrays int nextOffset; int bucketOffset; int totalSize = CalculateDataLayout( capacity, bucketLength, out nextOffset, out bucketOffset); state->Items = (byte *)UnsafeUtility.Malloc( totalSize, JobsUtility.CacheLineSize, allocator); state->Next = state->Items + nextOffset; state->Buckets = state->Items + bucketOffset; m_State = state; #if ENABLE_UNITY_COLLECTIONS_CHECKS #if UNITY_2018_3_OR_NEWER DisposeSentinel.Create( out m_Safety, out m_DisposeSentinel, 1, allocator); #else DisposeSentinel.Create( out m_Safety, out m_DisposeSentinel, 1); #endif #endif Clear(); }
public NativeArrayViewHandle(ulong gcHandle, AtomicSafetyHandle safety, DisposeSentinel disposeSentinel) { m_Safety = safety; m_DisposeSentinel = disposeSentinel; m_GCHandle = gcHandle; }
public static void Recycle(DisposeSentinel <T, TProvider> system) { current.PoolRecycle(ref system); }