示例#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 = CreateConatiner();
            }

            container.Consume();
            lookup.Add(container.Item, container);
            return(container.Item);
        }
示例#2
0
        private ObjectPoolContainer <T> CreateConatiner()
        {
            var container = new ObjectPoolContainer <T>();

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