33 lines
720 B
C#
33 lines
720 B
C#
/*
|
|
* 普通对象池
|
|
*/
|
|
|
|
using System;
|
|
|
|
namespace AibisDream.Kit
|
|
{
|
|
public class SimpleObjectPool<T> : Pool<T>
|
|
{
|
|
readonly Action<T> mResetMethod;
|
|
|
|
public SimpleObjectPool(Func<T> factoryMethod, Action<T> resetMethod = null, int initCount = 0)
|
|
{
|
|
mFactory = new CustomObjectFactory<T>(factoryMethod);
|
|
mResetMethod = resetMethod;
|
|
|
|
for (var i = 0; i < initCount; i++)
|
|
{
|
|
mCacheStack.Push(mFactory.Create());
|
|
}
|
|
}
|
|
|
|
public override bool Recycle(T obj)
|
|
{
|
|
mResetMethod?.Invoke(obj);
|
|
|
|
mCacheStack.Push(obj);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
} |