示例#1
0
        private void SetCapacity(int capacity)
        {
            var newarray = PoolArray <T> .Spawn(capacity);

            if (this.size > 0)
            {
                if (this.head < this.tail)
                {
                    Array.Copy(this.array.arr, this.head, newarray.arr, 0, this.size);
                }
                else
                {
                    Array.Copy(this.array.arr, this.head, newarray.arr, 0, this.array.Length - this.head);
                    Array.Copy(this.array.arr, 0, newarray.arr, this.array.Length - this.head, this.tail);
                }
            }

            if (this.array.arr != null)
            {
                PoolArray <T> .Recycle(ref this.array);
            }

            this.array = newarray;
            this.head  = 0;
            this.tail  = this.size == capacity ? 0 : this.size;
            this.version++;
        }
示例#2
0
        public void SetCapacity(int min)
        {
            if (this.Capacity < min)
            {
                var prevLength = this.Capacity;
                this.Capacity *= 2;
                if (this.Capacity < min)
                {
                    this.Capacity = min;
                }

                var newArray = PoolArray <T> .Spawn(this.Capacity);

                if (this.tail > this.head)                                                               // If we are not wrapped around...
                {
                    Array.Copy(this.innerArray.arr, this.head, newArray.arr, 0, this.Count);             // ...take from head to head+Count and copy to beginning of new array
                }
                else if (this.Count > 0)                                                                 // Else if we are wrapped around... (tail == head is ambiguous - could be an empty buffer or a full one)
                {
                    Array.Copy(this.innerArray.arr, this.head, newArray.arr, 0, prevLength - this.head); // ...take head to end and copy to beginning of new array
                    Array.Copy(this.innerArray.arr, 0, newArray.arr, prevLength - this.head, this.tail); // ...take beginning to tail and copy after previously copied elements
                }

                this.head = 0;
                this.tail = this.Count;
                if (this.innerArray.isNotEmpty == true)
                {
                    PoolArray <T> .Recycle(ref this.innerArray);
                }

                this.innerArray = newArray;
            }
        }
示例#3
0
        public void OnSpawn()
        {
            this.innerArray = PoolArray <T> .Spawn(this.Capacity);

            this.head  = 0;
            this.tail  = 0;
            this.Count = 0;
        }
示例#4
0
 public QueueCopyable(int capacity)
 {
     this.Capacity   = capacity;
     this.head       = 0;
     this.tail       = 0;
     this.Count      = 0;
     this.innerArray = PoolArray <T> .Spawn(this.Capacity);
 }
示例#5
0
        public BufferArrayBool(BufferArrayBool arr, int length)
        {
            this.arr = PoolArray <StorageType> .Spawn(length / BufferArrayBool.SIZE + 1);

            this.Length    = length;
            this.isCreated = true;
            System.Array.Copy(arr.arr.arr, this.arr.arr, arr.Length);
        }
示例#6
0
        public static BufferArray <T> From(BufferArray <T> arr)
        {
            var length = arr.Length;
            var buffer = PoolArray <T> .Spawn(length);

            ArrayUtils.Copy(arr, ref buffer);

            return(buffer);
        }
示例#7
0
        public QueueCopyable(int capacity)
        {
            this.capacity = capacity;
            this.array    = PoolArray <T> .Spawn(capacity);

            this.head = 0;
            this.tail = 0;
            this.size = 0;
        }
示例#8
0
        public BufferArrayBool(bool[] arr, int length)
        {
            this.arr = PoolArray <StorageType> .Spawn(length / BufferArrayBool.SIZE + 1);

            this.Length    = length;
            this.isCreated = true;
            if (arr != null)
            {
                for (int i = 0; i < length; ++i)
                {
                    this[i] = arr[i];
                }
            }
        }
示例#9
0
        public void CopyFrom(QueueCopyable <T> other)
        {
            if (this.array.arr != null)
            {
                PoolArray <T> .Recycle(ref this.array);
            }
            this.array = PoolArray <T> .Spawn(other.array.Length);

            System.Array.Copy(other.array.arr, this.array.arr, other.array.Length);

            this.head     = other.head;
            this.tail     = other.tail;
            this.size     = other.size;
            this.version  = other.version;
            this.capacity = other.capacity;
        }
示例#10
0
 public Enumerator(BufferArray <T> bufferArray)
 {
     this.bufferArray = bufferArray;
     this.index       = -1;
 }
示例#11
0
 public bool Equals(BufferArray <T> other)
 {
     return(this == other);
 }
示例#12
0
 public QueueCopyable()
 {
     this.array = QueueCopyable <T> .emptyArray;
 }
示例#13
0
 void IPoolableSpawn.OnSpawn()
 {
     this.array = PoolArray <T> .Spawn(this.capacity);
 }
示例#14
0
 internal NativeBufferArray(BufferArray <T> arr)
 {
     this.Length = arr.Length;
     this.arr    = new NativeArray <T>(arr.arr, Allocator.Persistent);
 }