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;
|
||||
}
|
||||
|
||||
public void SetUnownedMemory(Memory<byte> memory)
|
||||
{
|
||||
AvailableMemory = memory;
|
||||
}
|
||||
|
||||
public void ResetMemory()
|
||||
{
|
||||
if (_memoryOwner is IMemoryOwner<byte> owner)
|
||||
{
|
||||
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
|
||||
|
|
|
|||
|
|
@ -341,8 +341,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.PipeW
|
|||
}
|
||||
else
|
||||
{
|
||||
// We can't use the pool so allocate an array
|
||||
newSegment.SetUnownedMemory(new byte[sizeHint]);
|
||||
// We can't use the recommended pool so use the ArrayPool
|
||||
newSegment.SetOwnedMemory(ArrayPool<byte>.Shared.Rent(sizeHint));
|
||||
}
|
||||
|
||||
_tailMemory = newSegment.AvailableMemory;
|
||||
|
|
|
|||
Loading…
Reference in New Issue