Beispiel #1
0
        /// <summary>
        /// 获取内存池[反射引用于 fastCSharp.memoryPoolProxy]
        /// </summary>
        /// <param name="size">缓冲区尺寸</param>
        /// <returns>内存池</returns>
        public static memoryPool GetOrCreate(int size)
        {
            if (size <= 0)
            {
                log.Error.Throw(log.exceptionType.IndexOutOfRange);
            }
            memoryPool pool;

            Monitor.Enter(poolLock);
            if (pools.TryGetValue(size, out pool))
            {
                Monitor.Exit(poolLock);
            }
            else
            {
                try
                {
                    pools.Add(size, pool = new memoryPool(size));
                }
                finally { Monitor.Exit(poolLock); }
            }
            return(pool);
        }
Beispiel #2
0
        /// <summary>
        /// 内存池
        /// </summary>
        /// <param name="size">缓冲区尺寸</param>
        public memoryPool(int size)
        {
            pool = objectPool <byte[]> .Create();

            Size = size;
        }