You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/MemoryPools/JetPool.cs

30 lines
981 B

using MemoryPools.Memory;
using System.Runtime.CompilerServices;
/*https://github.com/sidristij/memory-pools*/
namespace MemoryPools
{
public class JetPool<T> where T : class, new()
{
private readonly JetStack<T> _freeObjectsQueue = new JetStack<T>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Get() => _freeObjectsQueue.Count > 0 ? _freeObjectsQueue.Pop() : new T();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Return(T instance) => _freeObjectsQueue.Push(instance);
}
public class JetValPool<T>
{
private readonly JetStack<T> _freeObjectsQueue = new JetStack<T>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Get() => (_freeObjectsQueue.Count > 0 ? _freeObjectsQueue.Pop() : default(T))!;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Return(T instance) => _freeObjectsQueue.Push(instance);
}
}

Powered by TurnKey Linux.