コード例 #1
0
        public PooledByteBufferAllocator(int nHeapArena, int pageSize, int maxOrder,
                                         int tinyCacheSize, int smallCacheSize, int normalCacheSize)
        {
            Contract.Requires(nHeapArena >= 0);

            this.threadCache     = new PoolThreadLocalCache(this);
            this.tinyCacheSize   = tinyCacheSize;
            this.smallCacheSize  = smallCacheSize;
            this.normalCacheSize = normalCacheSize;
            this.chunkSize       = ValidateAndCalculateChunkSize(pageSize, maxOrder);

            int pageShifts = ValidateAndCalculatePageShifts(pageSize);

            if (nHeapArena > 0)
            {
                this.heapArenas = NewArenaArray <byte[]>(nHeapArena);
                var metrics = new List <IPoolArenaMetric>(this.heapArenas.Length);
                for (int i = 0; i < this.heapArenas.Length; i++)
                {
                    var arena = new HeapArena(this, pageSize, maxOrder, pageShifts, this.chunkSize);
                    this.heapArenas[i] = arena;
                    metrics.Add(arena);
                }
                this.heapArenaMetrics = metrics.AsReadOnly();
            }
            else
            {
                this.heapArenas       = null;
                this.heapArenaMetrics = new IPoolArenaMetric[0];
            }

            this.metric = new PooledByteBufferAllocatorMetric(this);
        }
コード例 #2
0
        public unsafe PooledByteBufferAllocator(bool preferDirect, int nHeapArena, int nDirectArena, int pageSize, int maxOrder,
                                                int tinyCacheSize, int smallCacheSize, int normalCacheSize)
            : base(preferDirect)
        {
            if (nHeapArena < 0)
            {
                ThrowHelper.ThrowArgumentException_PositiveOrZero(nHeapArena, ExceptionArgument.nHeapArena);
            }
            if (nDirectArena < 0)
            {
                ThrowHelper.ThrowArgumentException_PositiveOrZero(nHeapArena, ExceptionArgument.nDirectArena);
            }

            _threadCache     = new PoolThreadLocalCache(this);
            _tinyCacheSize   = tinyCacheSize;
            _smallCacheSize  = smallCacheSize;
            _normalCacheSize = normalCacheSize;
            _chunkSize       = ValidateAndCalculateChunkSize(pageSize, maxOrder);

            int pageShifts = ValidateAndCalculatePageShifts(pageSize);

            if (nHeapArena > 0)
            {
                _heapArenas = NewArenaArray <byte[]>(nHeapArena);
                var metrics = new List <IPoolArenaMetric>(_heapArenas.Length);
                for (int i = 0; i < _heapArenas.Length; i++)
                {
                    var arena = new HeapArena(this, pageSize, maxOrder, pageShifts, _chunkSize);
                    _heapArenas[i] = arena;
                    metrics.Add(arena);
                }
                _heapArenaMetrics = metrics.AsReadOnly();
            }
            else
            {
                _heapArenas       = null;
                _heapArenaMetrics = new IPoolArenaMetric[0];
            }

            if (nDirectArena > 0)
            {
                _directArenas = NewArenaArray <byte[]>(nDirectArena);
                var metrics = new List <IPoolArenaMetric>(_directArenas.Length);
                for (int i = 0; i < _directArenas.Length; i++)
                {
                    var arena = new DirectArena(this, pageSize, maxOrder, pageShifts, _chunkSize);
                    _directArenas[i] = arena;
                    metrics.Add(arena);
                }
                _directArenaMetrics = metrics.AsReadOnly();
            }
            else
            {
                _directArenas       = null;
                _directArenaMetrics = new IPoolArenaMetric[0];
            }

            _metric = new PooledByteBufferAllocatorMetric(this);
        }