音频内容
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 普通对象池
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user