public T GetPooledItem() { ObjectPoolHolder <T> holder = null; int nItems = itemsList.Count; for (int i = 0; i < nItems; i++) { m_lastIndex++; if (m_lastIndex > nItems - 1) { m_lastIndex = 0; } if (itemsList[m_lastIndex].InUse) { continue; } else { holder = itemsList[m_lastIndex]; break; } } if (holder == null && m_enableExpand) { holder = CreatePoolHolder(); } holder.Use(); storage.Add(holder.Item, holder); return(holder.Item); }
private ObjectPoolHolder <T> CreatePoolHolder() { var itemHolder = new ObjectPoolHolder <T>(); itemHolder.Item = builderFunction(); itemsList.Add(itemHolder); return(itemHolder); }