protected MemBufferBase(SegmentAllocator<S> allocator, int minSegmentsToAllocate, int maxSegmentsToAllocate, S initialSegments) { _segmentAllocator = allocator; _segmentSize = allocator.getSegmentSize(); _maxSegmentsForReuse = minSegmentsToAllocate; _maxSegmentsToAllocate = maxSegmentsToAllocate; // all but one of segments goes to the free list _firstFreeSegment = initialSegments.getNext(); // and first one is used as both head and tail initialSegments.relink(null); _head = _tail = initialSegments; // also, better initialize initial segment for writing and reading _head.initForWriting(); _head.initForReading(); _usedSegmentsCount = 1; // Sanity checks? if yes, uncomment this... /* int count = count(_firstFreeSegment); if (count != _freeSegmentCount) { throw new IllegalStateException("Bad initial _freeSegmentCount ("+_freeSegmentCount+"): but only got "+count+" linked"); } */ _freeSegmentCount = minSegmentsToAllocate-1; }
protected MemBufferBase(SegmentAllocator<S> allocator, int minSegmentsToAllocate, int maxSegmentsToAllocate, S initialSegments) { _segmentAllocator = allocator; _segmentSize = allocator.getSegmentSize(); _maxSegmentsForReuse = minSegmentsToAllocate; _maxSegmentsToAllocate = maxSegmentsToAllocate; // all but one of segments goes to the free list _firstFreeSegment = initialSegments.getNext(); // and first one is used as both head and tail initialSegments.relink(null); _head = _tail = initialSegments; // also, better initialize initial segment for writing and reading _head.initForWriting(); _head.initForReading(); _usedSegmentsCount = 1; // Sanity checks? if yes, uncomment this... /* int count = count(_firstFreeSegment); if (count != _freeSegmentCount) { throw new IllegalStateException("Bad initial _freeSegmentCount ("+_freeSegmentCount+"): but only got "+count+" linked"); } */ _freeSegmentCount = minSegmentsToAllocate-1; }
S next = old.finishReading(); --_usedSegmentsCount; _tail = next.initForReading();
S next = old.finishReading(); --_usedSegmentsCount; _tail = next.initForReading();