public void ResizeToAtLeast <T>(ref Buffer <T> buffer, int targetSize, int copyCount) where T : struct { //Only do anything if the new size is actually different from the current size. Debug.Assert(copyCount <= targetSize && copyCount <= buffer.Length, "Can't copy more elements than exist in the source or target buffers."); targetSize = GetCapacityForCount <T>(targetSize); if (buffer.Length != targetSize) //Note that we don't check for allocated status- for buffers, a length of 0 is the same as being unallocated. { TakeAtLeast(targetSize, out Buffer <T> newBuffer); if (buffer.Length > 0) { //Don't bother copying from or re-pooling empty buffers. They're uninitialized. buffer.CopyTo(0, ref newBuffer, 0, copyCount); ReturnUnsafely(buffer.Id); } else { Debug.Assert(copyCount == 0, "Should not be trying to copy elements from an empty span."); } buffer = newBuffer; } }
public void Resize <T>(ref Buffer <T> buffer, int targetSize, int copyCount) { //Only do anything if the new size is actually different from the current size. targetSize = BufferPool <T> .GetLowestContainingElementCount(targetSize); if (buffer.Length != targetSize) //Note that we don't check for allocated status- for buffers, a length of 0 is the same as being unallocated. { Take(targetSize, out Buffer <T> newBuffer); if (buffer.Length > 0) { //Don't bother copying from or re-pooling empty buffers. They're uninitialized. buffer.CopyTo(0, ref newBuffer, 0, copyCount); ReturnUnsafely(buffer.Id); } else { Debug.Assert(copyCount == 0, "Should not be trying to copy elements from an empty span."); } buffer = newBuffer; } }