BufferSegment use ArrayPool for over-sized allocs (#13495)
This commit is contained in:
parent
725fa34cc8
commit
9399f09b72
|
|
@ -59,20 +59,16 @@ namespace System.IO.Pipelines
|
||||||
AvailableMemory = arrayPoolBuffer;
|
AvailableMemory = arrayPoolBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetUnownedMemory(Memory<byte> memory)
|
|
||||||
{
|
|
||||||
AvailableMemory = memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResetMemory()
|
public void ResetMemory()
|
||||||
{
|
{
|
||||||
if (_memoryOwner is IMemoryOwner<byte> owner)
|
if (_memoryOwner is IMemoryOwner<byte> owner)
|
||||||
{
|
{
|
||||||
owner.Dispose();
|
owner.Dispose();
|
||||||
}
|
}
|
||||||
else if (_memoryOwner is byte[] array)
|
else
|
||||||
{
|
{
|
||||||
ArrayPool<byte>.Shared.Return(array);
|
byte[] poolArray = (byte[])_memoryOwner;
|
||||||
|
ArrayPool<byte>.Shared.Return(poolArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order of below field clears is significant as it clears in a sequential order
|
// Order of below field clears is significant as it clears in a sequential order
|
||||||
|
|
|
||||||
|
|
@ -341,8 +341,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.PipeW
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We can't use the pool so allocate an array
|
// We can't use the recommended pool so use the ArrayPool
|
||||||
newSegment.SetUnownedMemory(new byte[sizeHint]);
|
newSegment.SetOwnedMemory(ArrayPool<byte>.Shared.Rent(sizeHint));
|
||||||
}
|
}
|
||||||
|
|
||||||
_tailMemory = newSegment.AvailableMemory;
|
_tailMemory = newSegment.AvailableMemory;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue