Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 public void Return()
 {
     if (_returnFunction == null)
     {
         return;
     }
     Reset();
     _returnFunction.Invoke(this);
     _returnFunction = null;
 }
Ejemplo n.º 3
0
 public void Return()
 {
     if (_returnFunction == null)
     {
         return;
     }
     Reset();
     _returnFunction.Invoke(this);
     _returnFunction = null;
 }
Ejemplo n.º 4
0
        internal void Return()
        {
            Reset();

            if (_returnToPoolDelegate == null)
            {
                return;
            }

            _returnToPoolDelegate.Invoke(this);
            _returnToPoolDelegate = null;
        }
Ejemplo n.º 5
0
        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());
            //}
        }
Ejemplo n.º 6
0
 void IPoolable.Initialize(ReturnToPoolDelegate returnFunction)
 {
     _returnFunction = returnFunction;
 }
Ejemplo n.º 7
0
 void IPoolable.Initialize(ReturnToPoolDelegate returnDelegate)
 {
     Reset();
 }
Ejemplo n.º 8
0
 void IPoolable.Initialize(ReturnToPoolDelegate returnFunction)
 {
     _returnFunction = returnFunction;
 }