예제 #1
0
        /// <summary>
        /// Clamps all values to the required limits.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method is necessary since the default structure is invalid.
        /// </para>
        /// </remarks>
        /// <param name="settings">The settings to clamp.</param>
        public static SimplePoolParams EnforceLimits(SimplePoolParams settings)
        {
            settings.MaximumPooled = settings.m_MaximumPooled;
            settings.PreloadCount  = settings.m_PreloadCount;

            return(settings);
        }
예제 #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="settings">The pool settings.</param>
        /// <param name="factoryMethod">
        /// The method for creating new instances of the pooled objects.
        /// </param>
        public SimplePool(SimplePoolParams settings, System.Func <T> factoryMethod)
        {
            if (factoryMethod == null)
            {
                throw new System.ArgumentNullException("factoryMethod");
            }

            m_FactoryMethod = factoryMethod;

            m_Settings = SimplePoolParams.EnforceLimits(m_Settings);

            m_Pool = new Stack <T>(m_Settings.MaximumPooled);

            while (m_Pool.Count <= m_Settings.PreloadCount)
            {
                m_Pool.Push(m_FactoryMethod());
            }
        }