Ejemplo n.º 1
0
        public void ReturnPoolItem(T item)
        {
            PooleableObject <T> poolObject = null;

            if (0 < this.unusedQueue.Count)
            {
                poolObject      = this.unusedQueue.Dequeue();
                poolObject.item = item;
            }
            else
            {
                poolObject = new PooleableObject <T>(item);
            }

            this.itemQueue.Enqueue(poolObject);
        }
Ejemplo n.º 2
0
        public T GetPoolItem()
        {
            T item = default;

            if (0 < this.itemQueue.Count)
            {
                PooleableObject <T> poolObject = this.itemQueue.Dequeue();
                this.unusedQueue.Enqueue(poolObject);
                item = poolObject.item;
            }
            else
            {
                item = this.Create();
            }

            return(item);
        }