Ejemplo n.º 1
0
 public PoolPage(PoolChunk chunk, int memoryMapIdx, int runOffset, int pageSize, int elemSize)
 {
     _chunk = chunk;
     _memoryMapIdx = memoryMapIdx;
     _runOffset = runOffset;
     _pageSize = pageSize;
     _bitmap = new long[pageSize >> 10];
     this.Init(elemSize);
 }
Ejemplo n.º 2
0
 public void Free(PoolChunk chunk, long handle, int maxLength)
 {
     lock (_sync)
     {
         if (!chunk.Unpooled)
         {
             chunk.Free(handle);
         }
     }
 }
Ejemplo n.º 3
0
 internal void Init(PoolChunk chunk, long handle, int offset, int length, int maxLength)
 {
     _chunk     = chunk;
     _buffer    = chunk.Buffer;
     _handle    = handle;
     _offset    = offset;
     _capacity  = length;
     _maxLength = maxLength;
     this.SetIndex(0, 0);
 }
Ejemplo n.º 4
0
 private void Allocate(PooledByteBuffer buffer, int reqCapacity, int normCapacity)
 {
     lock (_sync)
     {
         if (_chunkPools.Allocate(buffer, reqCapacity, normCapacity))
         {
             return;
         }
         var chunk  = new PoolChunk(this, _pageSize, _maxOrder, _pageShifts, _chunkSize);
         var handle = chunk.Allocate(normCapacity);
         chunk.InitBuffer(buffer, handle, reqCapacity);
         _chunkPools.Add(chunk);
     }
 }
Ejemplo n.º 5
0
 public void Add(PoolChunk chunk)
 {
     if (_head == null)
     {
         _head      = chunk;
         chunk.Prev = chunk.Next = null;
     }
     else
     {
         chunk.Prev = null;
         chunk.Next = _head;
         _head.Prev = chunk;
         _head      = chunk;
     }
     _totalChunks++;
 }
Ejemplo n.º 6
0
        public void Allocate(PooledByteBuffer buffer, int reqCapacity)
        {
            var normCapacity = this.NormalizeCapacity(reqCapacity);

            if (this.IsTinyOrSmall(normCapacity))
            {
                var        tableIdx = 0;
                PoolPage[] table;
                if ((normCapacity & 0xFFFFFE00) == 0)
                {
                    tableIdx = normCapacity >> 4;
                    table    = _tinySubpagePools;
                }
                else
                {
                    tableIdx = 0;
                    var i = normCapacity >> 10;//1024
                    while (i != 0)
                    {
                        i >>= 1;
                        tableIdx++;
                    }
                    table = _smallSubpagePools;
                }
                lock (_sync)
                {
                    var head = table[tableIdx];
                    var s    = head.Next;
                    if (s != head)
                    {
                        long handle = s.Allocate();
                        s.Chunk.InitBufferWithSubpage(buffer, handle, reqCapacity);
                        return;
                    }
                }
            }
            else if (normCapacity > _chunkSize)
            {
                var unpooledChunk = new PoolChunk(this, normCapacity);
                buffer.Init(unpooledChunk, 0, 0, reqCapacity, normCapacity);
                return;
            }
            this.Allocate(buffer, reqCapacity, normCapacity);
        }
Ejemplo n.º 7
0
 public void Allocate(PooledByteBuffer buffer, int reqCapacity)
 {
     var normCapacity = this.NormalizeCapacity(reqCapacity);
     if (this.IsTinyOrSmall(normCapacity))
     {
         var tableIdx = 0;
         PoolPage[] table;
         if ((normCapacity & 0xFFFFFE00) == 0)
         {
             tableIdx = normCapacity >> 4;
             table = _tinySubpagePools;
         }
         else
         {
             tableIdx = 0;
             var i = normCapacity >> 10;//1024
             while (i != 0)
             {
                 i >>= 1;
                 tableIdx++;
             }
             table = _smallSubpagePools;
         }
         lock (_sync)
         {
             var head = table[tableIdx];
             var s = head.Next;
             if (s != head)
             {
                 long handle = s.Allocate();
                 s.Chunk.InitBufferWithSubpage(buffer, handle, reqCapacity);
                 return;
             }
         }
     }
     else if (normCapacity > _chunkSize)
     {
         var unpooledChunk = new PoolChunk(this, normCapacity);
         buffer.Init(unpooledChunk, 0, 0, reqCapacity, normCapacity);
         return;
     }
     this.Allocate(buffer, reqCapacity, normCapacity);
 }
Ejemplo n.º 8
0
 private void Remove(PoolChunk cur)
 {
     if (cur == _head)
     {
         _head = cur.Next;
         if (_head != null)
         {
             _head.Prev = null;
         }
     }
     else
     {
         var next = cur.Next;
         cur.Prev.Next = next;
         if (next != null)
         {
             next.Prev = cur.Prev;
         }
     }
     _totalChunks--;
 }
Ejemplo n.º 9
0
 private void Remove(PoolChunk cur)
 {
     if (cur == _head)
     {
         _head = cur.Next;
         if (_head != null)
         {
             _head.Prev = null;
         }
     }
     else
     {
         var next = cur.Next;
         cur.Prev.Next = next;
         if (next != null)
         {
             next.Prev = cur.Prev;
         }
     }
     _totalChunks--;
 }
Ejemplo n.º 10
0
 public void Add(PoolChunk chunk)
 {
     if (_head == null)
     {
         _head = chunk;
         chunk.Prev = chunk.Next = null;
     }
     else
     {
         chunk.Prev = null;
         chunk.Next = _head;
         _head.Prev = chunk;
         _head = chunk;
     }
     _totalChunks++;
 }
Ejemplo n.º 11
0
 private void Allocate(PooledByteBuffer buffer, int reqCapacity, int normCapacity)
 {
     lock (_sync)
     {
         if (_chunkPools.Allocate(buffer, reqCapacity, normCapacity))
         {
             return;
         }
         var chunk = new PoolChunk(this, _pageSize, _maxOrder, _pageShifts, _chunkSize);
         var handle = chunk.Allocate(normCapacity);
         chunk.InitBuffer(buffer, handle, reqCapacity);
         _chunkPools.Add(chunk);
     }
 }
Ejemplo n.º 12
0
 public void Free(PoolChunk chunk, long handle, int maxLength)
 {
     lock (_sync)
     {
         if (!chunk.Unpooled)
         {
             chunk.Free(handle);
         }
     }
 }
Ejemplo n.º 13
0
 internal void Init(PoolChunk chunk, long handle, int offset, int length, int maxLength)
 {           
     _chunk = chunk;
     _buffer = chunk.Buffer;
     _handle = handle;
     _offset = offset;
     _capacity = length;
     _maxLength = maxLength;
     this.SetIndex(0, 0);
 }