Beispiel #1
0
        internal static void Return <T>(ref T[] buffer)
        {
            ACache.BufferDescriptor       key = new ACache.BufferDescriptor(typeof(T), buffer.Length);
            Stack <ACache.IBufferStorage> stack;

            if (!ACache.buffers.TryGetValue(key, out stack))
            {
                throw new InvalidOperationException("Returning a buffer that's never been taken!");
            }
            stack.Push((ACache.IBufferStorage) new ACache.BufferStorage <T>(buffer));
        }
Beispiel #2
0
        internal static T[] Get <T>(int elements, bool clearFirst)
        {
            ACache.BufferDescriptor       key = new ACache.BufferDescriptor(typeof(T), elements);
            Stack <ACache.IBufferStorage> stack;

            if (!ACache.buffers.TryGetValue(key, out stack))
            {
                ACache.buffers.Add(key, stack = new Stack <ACache.IBufferStorage>());
            }
            T[] objArray = stack.Count != 0 ? ((ACache.BufferStorage <T>)stack.Pop()).Buffer : new T[elements];
            if (clearFirst)
            {
                for (int index = 0; index < elements; ++index)
                {
                    objArray[index] = default(T);
                }
            }
            return(objArray);
        }