Esempio n. 1
0
 /// <inheritdoc />
 public virtual void ReturnObject(TPooledObject objectToRelease)
 {
     if (UsedObjectStore.Contains(objectToRelease))
     {
         UsedObjectStore.Remove(objectToRelease);
         UnusedObjectStore.Add(objectToRelease);
     }
 }
Esempio n. 2
0
        /// <inheritdoc />
        public virtual TPooledObject GetObject()
        {
            EnsureCapacity(1);
            TPooledObject newPooledObject = UnusedObjectStore.Pop();

            if (newPooledObject != null)
            {
                UsedObjectStore.Add(newPooledObject);
            }

            return(newPooledObject);
        }
Esempio n. 3
0
        /// <inheritdoc />
        public virtual void ClearAvailableObjects()
        {
            if (ObjectDisposer != null)
            {
                foreach (var unusedObject in UnusedObjectStore)
                {
                    ObjectDisposer.Dispose(unusedObject);
                }
            }

            UnusedObjectStore.Clear();
        }
Esempio n. 4
0
        /// <inheritdoc />
        public virtual void EnsureCapacity(int requestedCapacity)
        {
            while (UnusedObjectStore.Count < requestedCapacity)
            {
                if (UnusedObjectStore.Count + UsedObjectStore.Count == MaximumObjects)
                {
                    return;
                }

                TPooledObject newPooledObject = ObjectFactory.Create();
                UnusedObjectStore.Add(newPooledObject);
            }
        }