Exemplo n.º 1
0
        /// <summary>
        /// 获取内存池
        /// </summary>
        /// <param name="size">缓冲区尺寸</param>
        /// <returns>内存池</returns>
        public static unmanagedPool GetOrCreate(int size)
        {
            if (size <= 0)
            {
                log.Error.Throw(log.exceptionType.IndexOutOfRange);
            }
            unmanagedPool pool;

            Monitor.Enter(poolLock);
            if (pools.TryGetValue(size, out pool))
            {
                Monitor.Exit(poolLock);
            }
            else
            {
                try
                {
                    pools.Add(size, pool = new unmanagedPool(size));
                }
                finally { Monitor.Exit(poolLock); }
            }
            return(pool);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 内存池
        /// </summary>
        /// <param name="size">缓冲区尺寸</param>
        public unmanagedPool(int size)
        {
            pool = arrayPool <pointer> .Create();

            Size = size;
        }