mirror of
https://github.com/RRQM/TouchSocket.git
synced 2025-12-18 01:16:44 +08:00
update src/TouchSocket.Core/Pool/ByteManager/ByteBlock.cs.
构造函数设置租用字节数组的最小长度,以防为0或者负数 Signed-off-by: Sunny <yhuse@163.com>
This commit is contained in:
@@ -57,6 +57,8 @@ public sealed partial class ByteBlock : DisposableObject, IByteBlock
|
||||
/// <param name="byteSize">ByteBlock 的初始大小。</param>
|
||||
public ByteBlock(int byteSize)
|
||||
{
|
||||
//设置租用字节数组的最小长度,以防为0或者负数
|
||||
byteSize = Math.Max(16, byteSize);
|
||||
// 使用默认字节池初始化。
|
||||
this.m_bytePool = ArrayPool<byte>.Shared;
|
||||
// 从字节池租用指定大小的字节数组。
|
||||
@@ -72,6 +74,8 @@ public sealed partial class ByteBlock : DisposableObject, IByteBlock
|
||||
{
|
||||
// 确保字节池不为空。
|
||||
this.m_bytePool = ThrowHelper.ThrowArgumentNullExceptionIf(bytePool, nameof(bytePool));
|
||||
//设置租用字节数组的最小长度,以防为0或者负数
|
||||
byteSize = Math.Max(16, byteSize);
|
||||
// 从指定的字节池租用字节数组。
|
||||
this.m_buffer = bytePool.Rent(byteSize);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user