public T Create() { ObjectPoolContainer <T> container = null; for (int i = 0; i < _list.Count; i++) { _lastIndex++; if (_lastIndex > _list.Count - 1) { _lastIndex = 0; } if (_list[_lastIndex].Used == false) { container = _list[_lastIndex]; break; } } if (container == null) { container = BuildPool(); } container.Consume(); _lookup.Add(container.Item, container); return(container.Item); }
private ObjectPoolContainer <T> BuildPool() { var pool = new ObjectPoolContainer <T> { Item = _factoryFunc() }; _list.Add(pool); return(pool); }