10using System.Collections.Generic;
15 public static class ArrayPool<T> {
16 private static Dictionary<int, Stack<T[]>> _bins;
19 _bins =
new Dictionary<int, Stack<T[]>>();
21 _bins[0] =
new Stack<T[]>();
22 for (
int i = 0; i < 32; i++) {
23 _bins[1 << i] =
new Stack<T[]>();
35 public static T[] Spawn(
int minLength) {
36 int count = Mathf.NextPowerOfTwo(minLength);
37 var bin = _bins[count];
50 public static void Recycle(T[] array) {
51 Array.Clear(array, 0, array.Length);
52 int binKey = Mathf.NextPowerOfTwo(array.Length + 1) / 2;
53 _bins[binKey].Push(array);