mirror of https://github.com/ogoun/Zero.git
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.
19 lines
568 B
19 lines
568 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);
|
|
}
|
|
}
|