public static void Recycle(ref BufferArray <T> buffer) { //buffer = new BufferArray<T>(null, 0); //return; T[] arr = buffer.arr; PoolArray <T> .Release(ref arr); buffer = new BufferArray <T>(null, 0); }
public static BufferArray <T> Spawn(int length, bool realSize = false) { var arr = PoolArray <T> .Claim(length); var size = (realSize == true ? arr.Length : length); var buffer = new BufferArray <T>(arr, length, realSize == true ? arr.Length : -1); System.Array.Clear(buffer.arr, 0, size); return(buffer); }
public static BufferArray <T> Spawn(int length) { //return new BufferArray<T>(new T[length], length); //UnityEngine.Debug.Log("Spawn request: " + length); var buffer = new BufferArray <T>(PoolArray <T> .Claim(length), length); System.Array.Clear(buffer.arr, 0, length); return(buffer); }
public static void Recycle(ref BufferArray <T> buffer) { T[] arr = buffer.arr; if (arr != null) { System.Array.Clear(arr, 0, arr.Length); } PoolArray <T> .Release(ref arr); buffer = new BufferArray <T>(null, 0); }
void IPoolableRecycle.OnRecycle() { PoolHashSetCopyable <EntityId> .Recycle(ref this.dataContains); PoolHashSetCopyable <Entity> .Recycle(ref this.data); PoolArray <IFilterNode> .Recycle(ref this.nodes); PoolHashSet <Entity> .Recycle(ref this.requestsRemoveEntity); PoolHashSet <Entity> .Recycle(ref this.requests); }
void IPoolableSpawn.OnSpawn() { this.requests = PoolHashSet <Entity> .Spawn(Filter <TState, TEntity> .REQUESTS_CAPACITY); this.requestsRemoveEntity = PoolHashSet <Entity> .Spawn(Filter <TState, TEntity> .REQUESTS_CAPACITY); this.nodes = PoolArray <IFilterNode> .Spawn(Filter <TState, TEntity> .NODES_CAPACITY); this.data = PoolHashSetCopyable <Entity> .Spawn(); this.dataContains = PoolHashSetCopyable <EntityId> .Spawn(); }
public static void Recycle(BufferArray <T> buffer) { if (Pools.isActive == false) { buffer = default; return; } T[] arr = buffer.arr; //if (arr != null) System.Array.Clear(arr, 0, arr.Length); PoolArray <T> .Release(ref arr); }
public static NativeBufferArray <T> Spawn(int length, bool realSize = false, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent) { var arrSize = PoolArray <T> .GetSize(length); var arr = new Unity.Collections.NativeArray <T>(arrSize, allocator); var size = (realSize == true ? arr.Length : length); var buffer = new NativeBufferArray <T>(arr, length, realSize == true ? arr.Length : -1); NativeArrayUtils.Clear(buffer, 0, size); return(buffer); }
public static void Recycle <T, TCopy>(ref T[] item, TCopy copy) where TCopy : IArrayElementCopy <T> { if (item != null) { for (int i = 0; i < item.Length; ++i) { copy.Recycle(item[i]); } PoolArray <T> .Recycle(ref item); } }
public void Dispose() { for (int i = 0; i < this.itemsContains.Length; ++i) { this.itemsContains.arr[i].Dispose(); } PoolArray <Item> .Recycle(ref this.itemsContains); for (int i = 0; i < this.itemsNotContains.Length; ++i) { this.itemsNotContains.arr[i].Dispose(); } PoolArray <Item> .Recycle(ref this.itemsNotContains); }
/// <summary> /// Returns an array with at least the specified length. /// Warning: Returned arrays may contain arbitrary data. /// You cannot rely on it being zeroed out. /// </summary> internal static T[] Claim(int minimumLength) { //return new T[minimumLength]; if (minimumLength <= 0) { return(PoolArray <T> .empty); //PoolArray<T>.ClaimWithExactLength(0); } var bucketIndex = 0; while (1 << bucketIndex < minimumLength && bucketIndex < 30) { ++bucketIndex; } if (bucketIndex == 30) { throw new System.ArgumentException("Too high minimum length"); } if (PoolArray <T> .pool[0] == null) { PoolArray <T> .Initialize(); } if (PoolArray <T> .pool[bucketIndex].TryPop(out var result) == true) { return(result); } /*lock (PoolArray<T>.pool) { * * if (PoolArray<T>.pool[bucketIndex] == null) { * PoolArray<T>.pool[bucketIndex] = new System.Collections.Generic.Stack<T[]>(); * } * * if (PoolArray<T>.pool[bucketIndex].Count > 0) { * var array= PoolArray<T>.pool[bucketIndex].Pop(); * outArrays.Add(array); * return array; * } * * } * * var arr = new T[1 << bucketIndex]; * outArrays.Add(arr); * return arr;*/ return(new T[1 << bucketIndex]); }
internal void Deconstruct() { for (int i = 0; i < this.systems.Count; ++i) { this.systems.arr[i].OnDeconstruct(); if (this.systems.arr[i] is ISystemFilter systemFilter) { systemFilter.filter = null; } PoolSystems.Recycle(this.systems.arr[i]); } PoolArray <ISystemBase> .Recycle(ref this.systems); PoolArray <ModuleState> .Recycle(ref this.statesSystems); }
public static void Copy <T, TCopy>(T[] fromArr, ref T[] arr, TCopy copy) where TCopy : IArrayElementCopy <T> { if (fromArr == null) { if (arr != null) { for (int i = 0; i < arr.Length; ++i) { copy.Recycle(arr[i]); } PoolArray <T> .Recycle(ref arr); } arr = null; return; } if (arr == null || fromArr.Length != arr.Length) { if (arr != null) { ArrayUtils.Recycle(ref arr, copy); } arr = new T[fromArr.Length]; } var cnt = arr.Length; for (int i = 0; i < fromArr.Length; ++i) { var isDefault = i >= cnt; T item = (isDefault ? default : arr[i]); copy.Copy(fromArr[i], ref item); arr[i] = item; } }
public void Recycle() { PoolArray <ushort> .Recycle(ref this.values); }
internal static T[] Claim(int minimumLength) { //return new T[minimumLength]; if (minimumLength <= 0) { return(PoolArray <T> .empty); //PoolArray<T>.ClaimWithExactLength(0); } var bucketIndex = 0; while (1 << bucketIndex < minimumLength && bucketIndex < 30) { ++bucketIndex; } if (bucketIndex == 30) { throw new System.ArgumentException("Too high minimum length"); } if (PoolArray <T> .pool[0] == null) { PoolArray <T> .Initialize(); } #if MULTITHREAD_SUPPORT if (PoolArray <T> .pool[bucketIndex].TryPop(out var result) == true) { return(result); } #else var pool = PoolArray <T> .pool[bucketIndex]; if (pool.Count > 0) { var arrPooled = pool.Pop(); #if UNITY_EDITOR if (PoolArray <T> .outArrays.Contains(arrPooled) == true) { UnityEngine.Debug.LogError("You are trying to pool array that has been already in pool"); } PoolArray <T> .outArrays.Add(arrPooled); #endif //UnityEngine.Debug.Log("Spawn array: " + arrPooled + " :: " + arrPooled.GetHashCode()); return(arrPooled); } #endif /*lock (PoolArray<T>.pool) { * * if (PoolArray<T>.pool[bucketIndex] == null) { * PoolArray<T>.pool[bucketIndex] = new System.Collections.Generic.Stack<T[]>(); * } * * if (PoolArray<T>.pool[bucketIndex].Count > 0) { * var array= PoolArray<T>.pool[bucketIndex].Pop(); * outArrays.Add(array); * return array; * } * * } * * var arr = new T[1 << bucketIndex]; * outArrays.Add(arr); * return arr;*/ var arr = new T[1 << bucketIndex]; #if UNITY_EDITOR PoolArray <T> .outArrays.Add(arr); #endif //UnityEngine.Debug.Log("Spawn new array: " + arr + " :: " + arr.GetHashCode()); return(arr); }
partial void OnSpawnComponents() { this.componentsCache = PoolArray <IComponents <TState> > .Spawn(World <TState> .COMPONENTS_CAPACITY); //PoolDictionary<int, IComponents<TState>>.Spawn(World<TState>.COMPONENTS_CAPACITY); }
public void Initialize(int capacity) { this.buckets = PoolArray <Bucket> .Spawn(capacity); }
public void Dispose() { PoolArray <int> .Recycle(ref this.filters); }
public static void Copy <T, TCopy>(CCList <T> fromArr, ref CCList <T> arr, TCopy copy) where TCopy : IArrayElementCopy <T> { if (fromArr == null) { if (arr != null) { for (int i = 0; i < arr.Count; ++i) { copy.Recycle(arr[i]); } PoolCCList <T> .Recycle(ref arr); } arr = null; return; } if (arr != null) { for (int i = 0; i < arr.Count; ++i) { copy.Recycle(arr[i]); } PoolCCList <T> .Recycle(ref arr); } arr = PoolCCList <T> .Spawn(); arr.InitialCopyOf(fromArr); for (int i = 0; i < fromArr.array.Length; ++i) { if (fromArr.array[i] == null && arr.array[i] != null) { for (int k = 0; k < arr.array[i].Length; ++k) { copy.Recycle(arr.array[i][k]); } PoolArray <T> .Release(ref arr.array[i]); } else if (fromArr.array[i] != null && arr.array[i] == null) { arr.array[i] = PoolArray <T> .Claim(fromArr.array[i].Length); } else if (fromArr.array[i] == null && arr.array[i] == null) { continue; } var cnt = fromArr.array[i].Length; for (int j = 0; j < cnt; ++j) { copy.Copy(fromArr.array[i][j], ref arr.array[i][j]); } } /* * if (arr == null || fromArr.Count != arr.Count) { * * if (arr != null) { * * for (int i = 0; i < arr.Count; ++i) { * * copy.Recycle(arr[i]); * * } * * PoolCCList<T>.Recycle(ref arr); * * } * * arr = PoolCCList<T>.Spawn(); * arr.InitialCopyOf(fromArr); * * } * * for (int i = 0; i < fromArr.array.Length; ++i) { * * if (fromArr.array[i] == null && arr.array[i] != null) { * * for (int k = 0; k < arr.array[i].Length; ++k) { * * copy.Recycle(arr.array[i][k]); * * } * * PoolArray<T>.Release(ref arr.array[i]); * * } else if (fromArr.array[i] != null && arr.array[i] == null) { * * arr.array[i] = PoolArray<T>.Claim(fromArr.array[i].Length); * * } else if (fromArr.array[i] == null && arr.array[i] == null) { * * continue; * * } * * var cnt = fromArr.array[i].Length; * for (int j = 0; j < cnt; ++j) { * * copy.Copy(fromArr.array[i][j], ref arr.array[i][j]); * * } * * }*/ }
partial void OnRecycleComponents() { PoolArray <IComponents <TState> > .Recycle(ref this.componentsCache); //PoolDictionary<int, IComponents<TState>>.Recycle(ref this.componentsCache); }
public void OnRecycle() { PoolArray <Archetype> .Recycle(ref this.prevTypes); PoolArray <Archetype> .Recycle(ref this.types); }
public void OnRecycle() { PoolArray <uint> .Recycle(ref this.values); }