Example #1
0
        public T GetItem()
        {
            ObjectPoolContainer <T> container = null;

            foreach (var t in _list)
            {
                _lastIndex++;
                if (_lastIndex > _list.Count - 1)
                {
                    _lastIndex = 0;
                }

                if (_list[_lastIndex].Used)
                {
                    continue;
                }

                container = _list[_lastIndex];
                break;
            }

            if (container == null)
            {
                container = CreateContainer();
            }

            container.Consume();
            _lookup.Add(container.Item, container);
            return(container.Item);
        }
Example #2
0
        private ObjectPoolContainer <T> CreateContainer()
        {
            var container = new ObjectPoolContainer <T> {
                Item = _factoryFunc()
            };

            _list.Add(container);
            return(container);
        }