public synchronized long allocate(int length){
  int blocks=getBlockCount(length);
  BlockRange x=null;
  for (  BlockRange b : freeSpace) {
    if (b.blocks >= blocks) {
      x=b;
      break;
    }
  }
  long pos=getPos(x.start);
  if (x.blocks == blocks) {
    freeSpace.remove(x);
  }
 else {
    x.start+=blocks;
    x.blocks-=blocks;
  }
  return pos;
}

public synchronized long allocate ( int length ) { int blocks = getBlockCount ( length ) ; BlockRange x = null ; for ( BlockRange b : freeSpace ) { if ( b . blocks >= blocks ) { x = b ; break ; } } long pos = getPos ( x . start ) ; if ( x . blocks == blocks ) { freeSpace . remove ( x ) ; } else { x . start += blocks ; x . blocks -= blocks ; } return pos ; }
allocate a number of blocks and mark them as used .
