Beispiel #1
0
        /// <summary>
        ///     获取对象
        /// </summary>
        /// <param name="cout"></param>
        /// <returns></returns>
        public T[] GetObject(int cout)
        {
            T[] p = new T[cout];

            int Lpcout = ObjectStack.TryPopRange(p);


            if (Lpcout < cout)
            {
                int x = cout - Lpcout;

                T[] xp = new T[x];

                for (int i = 0; i < x; i++)
                {
                    xp[i] = GetT();
                }

                Array.Copy(xp, 0, p, Lpcout, x);
            }

            if (GetObjectRunTime != null)
            {
                for (int i = 0; i < p.Length; i++)
                {
                    p[i] = GetObjectRunTime(p[i], this);
                }
            }


            return(p);
        }
Beispiel #2
0
        /// <summary>
        ///     获取对象
        /// </summary>
        /// <param name="cout"></param>
        /// <returns></returns>
        public T[] GetObject(int cout)
        {
            if (ObjectStack.Count == 0)
            {
                var p = new T[cout];

                for (var i = 0; i < cout; i++)
                {
                    p[i] = GetT();
                    if (GetObjectRunTime != null)
                    {
                        p[i] = GetObjectRunTime(p[i], this);
                    }
                }

                return(p);
            }
            else
            {
#if USEConcurrent
                var p = new T[cout];

                var lpcout = ObjectStack.TryPopRange(p);


                if (lpcout < cout)
                {
                    var x = cout - lpcout;

                    var xp = new T[x];

                    for (var i = 0; i < x; i++)
                    {
                        xp[i] = GetT();
                    }

                    Array.Copy(xp, 0, p, lpcout, x);
                }

                if (GetObjectRunTime != null)
                {
                    for (var i = 0; i < p.Length; i++)
                    {
                        p[i] = GetObjectRunTime(p[i], this);
                    }
                }


                return(p);
#else
#if  lockStack == true
                lock (lockStack)
                {
#endif

                T[] p = new T[cout];

                for (int i = 0; i < cout; i++)
                {
                    if (ObjectStack.Count > 0)
                    {
                        p[i] = ObjectStack.Pop();

                        if (p[i] == null)
                        {
                            p[i] = GetT();
                        }
                    }
                    else
                    {
                        p[i] = GetT();
                    }


                    if (GetObjectRunTime != null)
                    {
                        p[i] = GetObjectRunTime(p[i], this);
                    }
                }

                return(p);

#if  lockStack == true
            }
#endif
#endif
            }
        }