Ejemplo n.º 1
0
        private void InitBufferWithSubpage(PooledByteBuffer buf, long handle, int bitmapIdx, int reqCapacity)
        {
            var memoryMapIdx = (int)handle;
            var idx          = this.PageIdx(memoryMapIdx);
            var subpage      = _subpages[idx];

            buf.Init(this, handle, this.RunOffset(memoryMapIdx) + (bitmapIdx & 0x3FFFFFFF) * subpage.ElemSize, reqCapacity, subpage.ElemSize);
        }
Ejemplo n.º 2
0
        public void InitBuffer(PooledByteBuffer buffer, long handle, int reqCapacity)
        {
            int memoryMapIdx = (int)handle;
            int bitmapIdx    = (int)(handle >> 32);

            if (bitmapIdx == 0)
            {
                //=pagesize
                buffer.Init(this, handle, this.RunOffset(memoryMapIdx), reqCapacity, this.RunLength(memoryMapIdx));
            }
            else
            {
                this.InitBufferWithSubpage(buffer, handle, bitmapIdx, reqCapacity);
            }
        }
Ejemplo n.º 3
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.º 4
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.º 5
0
 private void InitBufferWithSubpage(PooledByteBuffer buf, long handle, int bitmapIdx, int reqCapacity)
 {
     var memoryMapIdx = (int)handle;
     var idx = this.PageIdx(memoryMapIdx);
     var subpage = _subpages[idx];
     buf.Init(this, handle, this.RunOffset(memoryMapIdx) + (bitmapIdx & 0x3FFFFFFF) * subpage.ElemSize, reqCapacity, subpage.ElemSize);
 }
Ejemplo n.º 6
0
 public void InitBuffer(PooledByteBuffer buffer, long handle, int reqCapacity)
 {
     int memoryMapIdx = (int)handle;
     int bitmapIdx = (int)(handle >> 32);
     if (bitmapIdx == 0)
     {
         //=pagesize
         buffer.Init(this, handle, this.RunOffset(memoryMapIdx), reqCapacity, this.RunLength(memoryMapIdx));
     }
     else
     {
         this.InitBufferWithSubpage(buffer, handle, bitmapIdx, reqCapacity);
     }
 }