Пример #1
0
        /// <summary>
        /// Initializes the specified min and max pool size.
        /// </summary>
        /// <param name="minPoolSize">The min size of the pool.</param>
        /// <param name="maxPoolSize">The max size of the pool.</param>
        /// <param name="sourceCreator">The source creator.</param>
        public void Initialize(int minPoolSize, int maxPoolSize, ISmartPoolSourceCreator <T> sourceCreator)
        {
            m_MinPoolSize   = minPoolSize;
            m_MaxPoolSize   = maxPoolSize;
            m_SourceCreator = sourceCreator;
            m_GlobalStack   = new ConcurrentStack <T>();

            var n = 0;

            if (minPoolSize != maxPoolSize)
            {
                var currentValue = minPoolSize;

                while (true)
                {
                    n++;

                    var thisValue = currentValue * 2;

                    if (thisValue >= maxPoolSize)
                    {
                        break;
                    }

                    currentValue = thisValue;
                }
            }

            m_ItemsSource = new ISmartPoolSource[n + 1];

            T[] items;
            m_ItemsSource[0]     = sourceCreator.Create(minPoolSize, out items);
            m_CurrentSourceCount = 1;

            for (var i = 0; i < items.Length; i++)
            {
                m_GlobalStack.Push(items[i]);
            }

            m_TotalItemsCount = m_MinPoolSize;
        }
Пример #2
0
        /// <summary>
        /// Initializes the specified min and max pool size.
        /// </summary>
        /// <param name="minPoolSize">The min size of the pool.</param>
        /// <param name="maxPoolSize">The max size of the pool.</param>
        /// <param name="sourceCreator">The source creator.</param>
        public void Initialize(int minPoolSize, int maxPoolSize, ISmartPoolSourceCreator <T> sourceCreator)
        {
            m_minPoolSize   = minPoolSize;
            m_maxPoolSize   = maxPoolSize;
            m_sourceCreator = sourceCreator;
            m_globalStack   = new ConcurrentStack <T>();

            var n = 0;

            if (minPoolSize != maxPoolSize)
            {
                var currentValue = minPoolSize;

                while (true)
                {
                    n++;

                    var thisValue = currentValue * 2;

                    if (thisValue >= maxPoolSize)
                    {
                        break;
                    }

                    currentValue = thisValue;
                }
            }

            m_itemsSource = new ISmartPoolSource[n + 1];

            T[] items;
            m_itemsSource[0]     = sourceCreator.Create(minPoolSize, out items);
            m_currentSourceCount = 1;

            foreach (T t in items)
            {
                m_globalStack.Push(t);
            }
        }