Maintains a list of all of the memory allocations for the buffer pool.
This class is not thread safe.
Наследование: IDisposable
Пример #1
0
        /// <summary>
        /// Creates a new <see cref="MemoryPool"/>.
        /// </summary>
        /// <param name="pageSize">The desired page size. Must be between 4KB and 256KB</param>
        /// <param name="maximumBufferSize">The desired maximum size of the allocation. Note: could be less if there is not enough system memory.</param>
        /// <param name="utilizationLevel">Specifies the desired utilization level of the allocated space.</param>
        public MemoryPool(int pageSize = 64 * 1024, long maximumBufferSize = -1, TargetUtilizationLevels utilizationLevel = TargetUtilizationLevels.Low)
        {
            if (pageSize < 4096 || pageSize > 256 * 1024)
            {
                throw new ArgumentOutOfRangeException("pageSize", "Page size must be between 4KB and 256KB and a power of 2");
            }

            if (!BitMath.IsPowerOfTwo((uint)pageSize))
            {
                throw new ArgumentOutOfRangeException("pageSize", "Page size must be between 4KB and 256KB and a power of 2");
            }

            m_syncRoot     = new object();
            m_syncAllocate = new object();
            PageSize       = pageSize;
            PageMask       = PageSize - 1;
            PageShiftBits  = BitMath.CountBitsSet((uint)PageMask);

            m_pageList = new MemoryPoolPageList(PageSize, maximumBufferSize);
            m_requestCollectionEvent = new ThreadSafeList <WeakEventHandler <CollectionEventArgs> >();
            SetTargetUtilizationLevel(utilizationLevel);
        }
        /// <summary>
        /// Creates a new <see cref="MemoryPool"/>.
        /// </summary>
        /// <param name="pageSize">The desired page size. Must be between 4KB and 256KB</param>
        /// <param name="maximumBufferSize">The desired maximum size of the allocation. Note: could be less if there is not enough system memory.</param>
        /// <param name="utilizationLevel">Specifies the desired utilization level of the allocated space.</param>
        public MemoryPool(int pageSize = 64 * 1024, long maximumBufferSize = -1, TargetUtilizationLevels utilizationLevel = TargetUtilizationLevels.Low)
        {
            if (pageSize < 4096 || pageSize > 256 * 1024)
                throw new ArgumentOutOfRangeException("pageSize", "Page size must be between 4KB and 256KB and a power of 2");

            if (!BitMath.IsPowerOfTwo((uint)pageSize))
                throw new ArgumentOutOfRangeException("pageSize", "Page size must be between 4KB and 256KB and a power of 2");

            m_syncRoot = new object();
            m_syncAllocate = new object();
            PageSize = pageSize;
            PageMask = PageSize - 1;
            PageShiftBits = BitMath.CountBitsSet((uint)PageMask);

            m_pageList = new MemoryPoolPageList(PageSize, maximumBufferSize);
            m_requestCollectionEvent = new ThreadSafeList<WeakEventHandler<CollectionEventArgs>>();
            SetTargetUtilizationLevel(utilizationLevel);
        }