Ejemplo n.º 1
0
  /** Write a record to the sorter. */
  public void insertRecord(
      Object recordBaseObject, long recordBaseOffset, int lengthInBytes, long prefix)
      throws IOException {
    // Need 4 bytes to store the record length.
    final int totalSpaceRequired = lengthInBytes + 4;
    if (!haveSpaceForRecord(totalSpaceRequired)) {
      allocateSpaceForRecord(totalSpaceRequired);
    }

    final long recordAddress =
        memoryManager.encodePageNumberAndOffset(currentPage, currentPagePosition);
    final Object dataPageBaseObject = currentPage.getBaseObject();
    PlatformDependent.UNSAFE.putInt(dataPageBaseObject, currentPagePosition, lengthInBytes);
    currentPagePosition += 4;
    PlatformDependent.copyMemory(
        recordBaseObject, recordBaseOffset, dataPageBaseObject, currentPagePosition, lengthInBytes);
    currentPagePosition += lengthInBytes;
    freeSpaceInCurrentPage -= totalSpaceRequired;
    sorter.insertRecord(recordAddress, prefix);
  }