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

            for (int i = 0; i < list.Count; i++)
            {
                lastIndex++;
                if (lastIndex > list.Count - 1)
                {
                    lastIndex = 0;
                }

                if (list[lastIndex].Used)
                {
                    continue;
                }
                else
                {
                    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>();

            container.Item = factoryFunc();
            list.Add(container);
            return(container);
        }