private void ensureBufferCapacity(int desiredCapacity){
  int capacity=pixelBuffer.length;
  while (capacity < desiredCapacity) {
    capacity*=2;
  }
  if (capacity > pixelBuffer.length) {
    pixelBuffer=new byte[capacity];
  }
}

private void ensureBufferCapacity ( int desiredCapacity ) { int capacity = pixelBuffer . length ; while ( capacity < desiredCapacity ) { capacity *= 2 ; } if ( capacity > pixelBuffer . length ) { pixelBuffer = new byte [ capacity ] ; } }
grow the pixel buffer if necessary . using this method instead of allocating a new buffer every time a frame is grabbed improves performance by reducing the frequency of garbage collections . in a simple test , the unmodified version of ipcameraframegrabber caused about 200mb of allocations within 13 seconds . in this version , almost no additional heap space is typically allocated per frame . the downside to this is that the returned frames can ' t really be modified , so this probably won ' t go upstream , but it ' s useful for us because in grip we don ' t operate on images in - place .
