Ejemplo n.º 1
0
        public PooledByteBufferAllocator(
            bool preferDirect,
            int nHeapArena,
            int nDirectArena,
            int pageSize,
            int maxOrder,
            int tinyCacheSize,
            int smallCacheSize,
            int normalCacheSize)
            : base(preferDirect)
        {
            Contract.Requires(nHeapArena >= 0);
            Contract.Requires(nDirectArena >= 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];
            }

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

            this.metric = new PooledByteBufferAllocatorMetric(this);
        }
Ejemplo n.º 2
0
        public PooledArrayBufferAllocator(int heapArenaCount, int pageSize, int maxOrder,
                                          int tinyCacheSize, int smallCacheSize, int normalCacheSize, int maxChunkCountPerArena)
        {
            Contract.Requires(heapArenaCount >= 0);

            this.threadCache     = new PoolThreadLocalCache(this);
            this.TinyCacheSize   = tinyCacheSize;
            this.SmallCacheSize  = smallCacheSize;
            this.NormalCacheSize = normalCacheSize;
            int chunkSize = PoolOptions.ValidateAndCalculateChunkSize(pageSize, maxOrder);

            int pageShifts = PoolOptions.ValidateAndCalculatePageShifts(pageSize);

            if (heapArenaCount > 0)
            {
                this.heapArenas = NewArenaArray(heapArenaCount);
                var metrics = new List <IPoolArenaMetric>(this.heapArenas.Length);
                for (int i = 0; i < this.heapArenas.Length; i++)
                {
                    var arena = new PoolArena <T>(this, pageSize, maxOrder, pageShifts, chunkSize, maxChunkCountPerArena);
                    this.heapArenas[i] = arena;
                    metrics.Add(arena);
                }
                this.heapArenaMetrics = metrics.AsReadOnly();
            }
            else
            {
                this.heapArenas       = null;
                this.heapArenaMetrics = new List <IPoolArenaMetric>();
            }
        }
Ejemplo n.º 3
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);
        }