Esempio n. 1
0
 private void newBuffer() {
   this.buffer = allocator.allocate(PageFormat.PAGE_HEADER_SIZE + fixedRecordSize);
   this.bufferSlice = Slices.wrappedBuffer(buffer.array(), buffer.offset(), buffer.capacity());
   this.count = 0;
   this.position = PageFormat.PAGE_HEADER_SIZE;
   this.stringReferences.clear();
   this.stringReferenceSize = 0;
 }
Esempio n. 2
0
  public void addRecord() {
    // record header
    bufferSlice.setInt(
        position, nextVariableLengthDataOffset); // nextVariableLengthDataOffset means record size
    bufferSlice.setBytes(position + 4, nullBitSet);
    count++;

    this.position += nextVariableLengthDataOffset;
    this.nextVariableLengthDataOffset = fixedRecordSize;
    Arrays.fill(nullBitSet, (byte) -1);

    // flush if next record will not fit in this buffer
    if (buffer.capacity() < position + nextVariableLengthDataOffset + stringReferenceSize) {
      flush();
    }
  }
Esempio n. 3
0
  /* ------------------------------------------------------------ */
  public Buffer getBuffer(int size) {
    if (_otherHeaders && size == getHeaderSize()) return getHeader();
    if (_otherBuffers && size == getBufferSize()) return getBuffer();

    // Look for an other buffer
    Buffer buffer = _others.poll();

    // consume all other buffers until one of the right size is found
    while (buffer != null && buffer.capacity() != size) {
      _size.decrementAndGet();
      buffer = _others.poll();
    }

    if (buffer == null) buffer = newBuffer(size);
    else _size.decrementAndGet();
    return buffer;
  }
Esempio n. 4
0
 void _reset(Buffer b) {
   b.position(0);
   b.limit(b.capacity());
 }