/**
   * Allocates file space for the row.
   *
   * <p>A Row is added by walking the list of CacheFree objects to see if there is available space
   * to store it, reusing space if it exists. Otherwise the file is grown to accommodate it.
   */
  private int setFilePos(CachedObject r) throws IOException {

    int rowSize = r.getStorageSize();
    int i = freeBlocks == null ? -1 : freeBlocks.get(rowSize);

    if (i == -1) {
      i = (int) (fileFreePosition / cacheFileScale);

      long newFreePosition = fileFreePosition + rowSize;

      if (newFreePosition > maxDataFileSize) {
        throw new IOException(Trace.getMessage(Trace.DATA_FILE_IS_FULL));
      }

      fileFreePosition = newFreePosition;
    }

    r.setPos(i);

    return i;
  }