public T[] CheckOut(int size) { var logSize = BufferPoolUtils.Log2(size); if ((1 << logSize) < size) { throw new Exception("TLBP Exception !!!!!!!!!"); } if (logSize < stacks.Length && stacks[logSize].Count > 0) { return(stacks[logSize].Pop()); } else { try { T[] res = new T[1 << logSize]; return(res); } catch (Exception e) { Debug.Assert(false); Logging.Fatal("BufferPool.CheckOut exception {0}", e); Logging.Fatal("Size {0}, Type {1}", logSize, typeof(T)); Logging.Fatal(e.StackTrace); throw; } } }
public void CheckIn(T[] array) { if (array != null && array.Length > 0) { var size = BufferPoolUtils.Log2(array.Length); while ((1 << size) > array.Length) { size--; } if (size < stacks.Length && stacks[size].Count < MaximumStackLength) { stacks[size].Push(array); } } }
public T[] CheckOutInitialized(int size) { size = BufferPoolUtils.Log2(size); if (size < stacks.Length && stacks[size].Count > 0) { var array = stacks[size].Pop(); Array.Clear(array, 0, array.Length); return(array); } else { return(new T[1 << size]); } }