public ObjectPool(Func <T> instantiationFunc, int capacity = 16, ObjectPoolIsFullPolicy isFullPolicy = ObjectPoolIsFullPolicy.ReturnNull) { _instantiationFunction = instantiationFunc ?? throw new ArgumentNullException(nameof(instantiationFunc)); _returnToPoolDelegate = Return; _freeItems = new Deque <T>(capacity); IsFullPolicy = isFullPolicy; }
public void Return() { if (_returnFunction == null) { return; } Reset(); _returnFunction.Invoke(this); _returnFunction = null; }
internal void Return() { Reset(); if (_returnToPoolDelegate == null) { return; } _returnToPoolDelegate.Invoke(this); _returnToPoolDelegate = null; }
public ObjectPool(Func <T> instantiationFunc, int capacity = 16, ObjectPoolIsFullPolicy isFullPolicy = ObjectPoolIsFullPolicy.ReturnNull) { if (instantiationFunc == null) { throw new ArgumentNullException(nameof(instantiationFunc)); } _returnToPoolDelegate = Return; _instantiationFunction = instantiationFunc; _freeItems = new Deque <T>(capacity); IsFullPolicy = isFullPolicy; //while (_freeItems.Count < capacity) //{ // Capacity++; // _freeItems.AddToBack(CreateObject()); //} }
void IPoolable.Initialize(ReturnToPoolDelegate returnFunction) { _returnFunction = returnFunction; }
void IPoolable.Initialize(ReturnToPoolDelegate returnDelegate) { Reset(); }