初始化CRICS

This commit is contained in:
2025-12-11 09:17:16 +08:00
commit 83247ec0a2
2735 changed files with 787765 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
// 简易对象池
using System.Collections.Concurrent;
using System.IO;
public class SimpleMemoryStreamPool
{
private static readonly ConcurrentBag<MemoryStream> _pool = new ConcurrentBag<MemoryStream>();
private const int MaxPoolSize = 50;
public static MemoryStream Rent(int capacity = 1024)
{
MemoryStream stream;
if (_pool.TryTake(out stream))
{
stream.SetLength(0);
stream.Position = 0;
return stream;
}
return new MemoryStream(capacity);
}
public static void Return(MemoryStream stream)
{
if (stream != null && _pool.Count < MaxPoolSize)
{
stream.SetLength(0);
stream.Position = 0;
_pool.Add(stream);
}
}
}