Пример #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;
        }
Пример #2
0
 public void Return()
 {
     if (_returnFunction == null)
     {
         return;
     }
     Reset();
     _returnFunction.Invoke(this);
     _returnFunction = null;
 }
Пример #3
0
 public void Return()
 {
     if (_returnFunction == null)
     {
         return;
     }
     Reset();
     _returnFunction.Invoke(this);
     _returnFunction = null;
 }
Пример #4
0
        internal void Return()
        {
            Reset();

            if (_returnToPoolDelegate == null)
            {
                return;
            }

            _returnToPoolDelegate.Invoke(this);
            _returnToPoolDelegate = null;
        }
Пример #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());
            //}
        }
Пример #6
0
 void IPoolable.Initialize(ReturnToPoolDelegate returnFunction)
 {
     _returnFunction = returnFunction;
 }
 void IPoolable.Initialize(ReturnToPoolDelegate returnDelegate)
 {
     Reset();
 }
Пример #8
0
 void IPoolable.Initialize(ReturnToPoolDelegate returnFunction)
 {
     _returnFunction = returnFunction;
 }