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++; }
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; } }
public void OnSpawn() { this.innerArray = PoolArray <T> .Spawn(this.Capacity); this.head = 0; this.tail = 0; this.Count = 0; }
public QueueCopyable(int capacity) { this.Capacity = capacity; this.head = 0; this.tail = 0; this.Count = 0; this.innerArray = PoolArray <T> .Spawn(this.Capacity); }
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); }
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); }
public QueueCopyable(int capacity) { this.capacity = capacity; this.array = PoolArray <T> .Spawn(capacity); this.head = 0; this.tail = 0; this.size = 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]; } } }
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; }
public Enumerator(BufferArray <T> bufferArray) { this.bufferArray = bufferArray; this.index = -1; }
public bool Equals(BufferArray <T> other) { return(this == other); }
public QueueCopyable() { this.array = QueueCopyable <T> .emptyArray; }
void IPoolableSpawn.OnSpawn() { this.array = PoolArray <T> .Spawn(this.capacity); }
internal NativeBufferArray(BufferArray <T> arr) { this.Length = arr.Length; this.arr = new NativeArray <T>(arr.arr, Allocator.Persistent); }