未验证 提交 b3fee317 编写于 作者: L lindexi 提交者: GitHub

Using ArrayPool in RenderData (#5392)

* Using ArrayPool in RenderData

The max length is 72, see MILCMD_DRAW_ROUNDED_RECTANGLE_ANIMATE

* Remove the finalizer code in RenderData
上级 95c3da03
......@@ -15,6 +15,7 @@
using MS.Internal;
using MS.Utility;
using System;
using System.Buffers;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
......@@ -470,7 +471,7 @@ private void EnsureBuffer(int cbRequiredSize)
// If we don't have a buffer, this is easy: we simply allocate a new one of the appropriate size.
if (_buffer == null)
{
_buffer = new byte[cbRequiredSize];
_buffer = ArrayPool<byte>.Shared.Rent(cbRequiredSize);
}
else
{
......@@ -487,11 +488,20 @@ private void EnsureBuffer(int cbRequiredSize)
// this growth function is broken.
Debug.Assert(newSize >= cbRequiredSize);
byte[] _newBuffer = new byte[newSize];
byte[] newBuffer = ArrayPool<byte>.Shared.Rent(newSize);
_buffer.CopyTo(_newBuffer, 0);
unsafe
{
fixed (byte* pBuffer = _buffer)
fixed (byte* pNewBuffer = newBuffer)
{
Buffer.MemoryCopy(pBuffer, pNewBuffer, _buffer.Length, _buffer.Length);
}
}
_buffer = _newBuffer;
var oldBuffer = _buffer;
_buffer = newBuffer;
ArrayPool<byte>.Shared.Return(oldBuffer);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册