zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/Model/Core/Pool.cs

29 lines
518 B
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System.Collections.Generic;
namespace ET
{
public class Pool<T> where T: class, new()
{
private readonly Queue<T> pool = new Queue<T>();
public T Fetch()
{
if (pool.Count == 0)
{
return new T();
}
return pool.Dequeue();
}
public void Recycle(T t)
{
pool.Enqueue(t);
}
public void Clear()
{
this.pool.Clear();
}
}
}