Пример #1
0
 public PoolChunk(PoolArena arena, int pageSize, int maxOrder, int pageShifts, int chunkSize)
 {
     _arena = arena;
     _buffer = new byte[chunkSize];         
     _maxOrder = maxOrder;                     
     _pageSize = pageSize;
     _pageShifts = pageShifts;
     _freeBytes = _chunkSize = chunkSize;                         
     _unusable = (byte)(maxOrder + 1); 
     _maxSubpageAllocs = 1 << maxOrder;
     _memoryMap = new byte[_maxSubpageAllocs << 1];
     _depthMap = new byte[_memoryMap.Length];
     var memoryMapIndex = 1;
     for (var d = 0; d <= maxOrder; d++)
     { 
         var depth = 1 << d;
         for (int p = 0; p < depth; p++)
         {
             _memoryMap[memoryMapIndex] = (byte)d;
             _depthMap[memoryMapIndex] = (byte)d;
             memoryMapIndex++;
         }
     }
     _subpages = new PoolPage[_maxSubpageAllocs];
     _log2ChunkSize = Utils.Log2(chunkSize);
     _unpooled = false;
 }
Пример #2
0
 /// <summary>
 /// Initialize new instance of the <see cref="IBufferFactory"/>.
 /// </summary>
 /// <param name="numberArenas"></param>
 /// <param name="pageSize"></param>
 /// <param name="maxOrder"></param>
 public PooledBufferFactory(int numberArenas, int pageSize, int maxOrder)
 {
     if (numberArenas < 0)
     {
         throw new ArgumentException("numberArenas less than 0.");
     }
     if (pageSize < 4096 || (pageSize & pageSize - 1) != 0)
     {
         throw new ArgumentException("pageSize less than 4096 or not is power of 2.");
     }
     if ((pageSize << maxOrder) > MAX_CHUNK_SIZE)
     {
         throw new ArgumentException(string.Format("The size of each of chunk cannot be greater than {0} bytes.", MAX_CHUNK_SIZE), "pageSize and maxOrder");
     }
     if (maxOrder < 0)
     {
         throw new ArgumentException("maxOrder less than 0.");
     }
     _arenas = new PoolArena[numberArenas];
     for (var i = 0; i < numberArenas; i++)
     {
         _arenas[i] = new PoolArena("arena_" + i, pageSize, maxOrder, pageSize << maxOrder);
     }
 }
Пример #3
0
 public PoolChunk(PoolArena arena, int chunkSize)
 {
     _unpooled = true;
     _arena = arena;
     _buffer = new byte[chunkSize];
 }