chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:13:17 +08:00
commit 58ab8315aa
8961 changed files with 5602567 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
using System;
namespace T3.Core.Utils.ObjectPooling;
public sealed class ArrayPool<T>
{
private readonly ObjectPoolBase<T[]> _pool;
private readonly int _arrayLength;
public ArrayPool(bool concurrent, int arrayLength)
{
_arrayLength = arrayLength;
if (concurrent)
{
_pool = new ConcurrentObjectPool<T[]>(CreateFunc);
}
else
{
_pool = new ObjectPool<T[]>(CreateFunc);
}
}
public T[] Get() => _pool.Get();
public void Return(T[] obj, bool clear)
{
var length = _arrayLength;
if (obj.Length != length)
{
throw new ArgumentException("Invalid array length - this array did not come from this pool", nameof(obj));
}
if (clear)
{
for (var i = 0; i < length; i++)
{
obj[i] = default;
}
}
_pool.Return(obj);
}
private T[] CreateFunc()
{
return new T[_arrayLength];
}
}