Exemplo n.º 1
0
        /// <summary>
        /// Constructs a new container with the specified capacity and type of memory allocation.
        /// </summary>
        /// <param name="capacity">Container capacity.</param>
        /// <param name="allocator">A member of the
        /// [Unity.Collections.Allocator](https://docs.unity3d.com/ScriptReference/Unity.Collections.Allocator.html) enumeration.</param>
        /// <param name="options">Memory should be cleared on allocation or left uninitialized.</param>
        public UnsafeRingQueue(int capacity, Allocator allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory)
        {
            capacity += 1;

            Allocator = allocator;
            Control   = new RingControl(capacity);
            var sizeInBytes = capacity * UnsafeUtility.SizeOf <T>();

            Ptr = (T *)UnsafeUtility.Malloc(sizeInBytes, 16, allocator);

            if (options == NativeArrayOptions.ClearMemory)
            {
                UnsafeUtility.MemClear(Ptr, sizeInBytes);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs container as view into memory.
 /// </summary>
 /// <param name="ptr"></param>
 /// <param name="capacity"></param>
 public UnsafeRingQueue(T *ptr, int capacity)
 {
     Ptr       = ptr;
     Allocator = Allocator.Invalid;
     Control   = new RingControl(capacity);
 }