示例#1
0
        public static void Recycle(ref T[] buffer)
        {
            var length = buffer.Length;

            if (length == 0)
            {
                return;
            }
            if (length > PoolArray <T> .BLOCK_SIZE)
            {
                buffer = null;
                return;
            }
            PoolInternalBase pool;

            if (PoolArray <T> .pools.TryGetValue(length, out pool) == true)
            {
                pool.Recycle(buffer);
                buffer = null;
            }
            else
            {
                pool = PoolArray <T> .CreatePool(length);

                pool.Recycle(buffer);
                buffer = null;
                PoolArray <T> .pools.Add(length, pool);
            }
        }
示例#2
0
        public static T[] Spawn(int length)
        {
            if (length == 0)
            {
                return(PoolArray <T> .emptyArray);
            }

            if (length > PoolArray <T> .BLOCK_SIZE)
            {
                return(new T[length]);
            }

            T[] result;
            PoolInternalBase pool;

            if (PoolArray <T> .pools.TryGetValue(length, out pool) == true)
            {
                result = (T[])pool.Spawn();
            }
            else
            {
                pool = PoolArray <T> .CreatePool(length);

                result = (T[])pool.Spawn();
                PoolArray <T> .pools.Add(length, pool);
            }

            return(result);
        }