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); }
public void Free(PoolChunk chunk, long handle, int maxLength) { lock (_sync) { if (!chunk.Unpooled) { chunk.Free(handle); } } }
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); }
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); } }
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++; }
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); }
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--; }