34 lines
727 B
C#
34 lines
727 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Encompass
|
|
{
|
|
internal class BitArrayPool
|
|
{
|
|
private Stack<BitArray> bitArrays;
|
|
|
|
public BitArrayPool(int capacity)
|
|
{
|
|
bitArrays = new Stack<BitArray>(capacity);
|
|
|
|
for (var i = 0; i < capacity; i++)
|
|
{
|
|
bitArrays.Push(new BitArray(128));
|
|
}
|
|
}
|
|
|
|
public BitArray Obtain(int size)
|
|
{
|
|
var bitArray = bitArrays.Pop();
|
|
bitArray.Length = size;
|
|
bitArray.SetAll(false);
|
|
return bitArray;
|
|
}
|
|
|
|
public void Free(BitArray bitArray)
|
|
{
|
|
bitArrays.Push(bitArray);
|
|
}
|
|
}
|
|
}
|