internal byte[] GetBlock()
{
byte[] block;
if (!this.smallPool.TryPop(out block))
{
// We'll add this back to the pool when the stream is disposed
// (unless our free pool is too large)
block = new byte[this.BlockSize];
Events.Write.MemoryStreamNewBlockCreated(this.smallPoolInUseSize);
if (this.BlockCreated != null)
{
this.BlockCreated();
}
}
else
{
Interlocked.Add(ref this.smallPoolFreeSize, -this.BlockSize);
}
Interlocked.Add(ref this.smallPoolInUseSize, this.BlockSize);
return block;
}