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

            for (var i = 0; i < _list.Count; i++)
            {
                _lastIndex++;

                if (_lastIndex > _list.Count - 1)
                {
                    _lastIndex = 0;
                }

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

                container = _list[_lastIndex];
                break;
            }

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

            container.Item = _factoryFunc();
            _list.Add(container);
            return(container);
        }