private void ExpandCapacity(int targetCapacity)
{
if (_chunkPool == null)
{
throw new InvalidOperationException("Capacity cannot be expanded because this buffer was created without specifying a chunk pool.");
}
while (_capacity < targetCapacity)
{
var chunk = _chunkPool.AcquireChunk();
chunk.IncrementReferenceCount();
_chunks.Add(chunk);
_capacity += _chunkSize;
}
}