25 lines
591 B
C#
25 lines
591 B
C#
using System;
|
|
using System.Buffers;
|
|
|
|
namespace AlicizaX.ObjectPool
|
|
{
|
|
/// <summary>
|
|
/// 数组池管理器,避免频繁分配数组
|
|
/// </summary>
|
|
internal static class SlotArrayPool<T>
|
|
{
|
|
private static readonly ArrayPool<T> s_Pool = ArrayPool<T>.Create(256, 50);
|
|
|
|
public static T[] Rent(int minimumLength)
|
|
{
|
|
return s_Pool.Rent(minimumLength);
|
|
}
|
|
|
|
public static void Return(T[] array, bool clearArray = false)
|
|
{
|
|
if (array != null)
|
|
s_Pool.Return(array, clearArray);
|
|
}
|
|
}
|
|
}
|