Exemplo n.º 1
0
        internal static T[] ClaimWithExactLength(int length)
        {
            var isPowerOfTwo = length != 0 && (length & (length - 1)) == 0;

            if (isPowerOfTwo)
            {
                // Will return the correct array length
                return(PoolArray <T> .Claim(length));
            }

            if (length <= PoolArray <T> .MaximumExactArrayLength)
            {
                var stack = PoolArray <T> .exactPool[length];
                return(stack.Pop());

                /*lock (PoolArray<T>.pool) {
                 *      var stack = PoolArray<T>.exactPool[length];
                 *      if (stack != null && stack.Count > 0) {
                 *              var array = stack.Pop();
                 *              return array;
                 *      }
                 * }*/
            }
            return(new T[length]);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        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]);
             *
             *  }
             *
             * }*/
        }