Ver.0.3.0.33

This commit is contained in:
2025-07-08 08:32:46 +00:00
parent 99f4dd67c2
commit 0ad5e29917
6831 changed files with 695623 additions and 234455 deletions
@@ -0,0 +1,45 @@
using System.Collections.Generic;
namespace AibisDream.Kit
{
public static class ListPool<T>
{
/// <summary>
/// 栈对象:存储多个List
/// </summary>
static readonly Stack<List<T>> ListStack = new(8);
/// <summary>
/// 出栈:获取某个List对象
/// </summary>
/// <returns></returns>
public static List<T> Get()
{
return ListStack.Count == 0 ? new List<T>(8) : ListStack.Pop();
}
/// <summary>
/// 入栈:将List对象添加到栈中
/// </summary>
/// <param name="toRelease"></param>
public static void Release(List<T> toRelease)
{
if (ListStack.Contains(toRelease))
{
throw new System.InvalidOperationException(
"重复回收 ListThe List is released even though it is in the pool");
}
toRelease.Clear();
ListStack.Push(toRelease);
}
}
public static class ListPoolExtensions
{
public static void Release2Pool<T>(this List<T> self)
{
ListPool<T>.Release(self);
}
}
}