@ Override public void relocate ( final int oldPosition , final int newPosition , final ByteBuffer oldBuf , final ByteBuffer newBuf ) { HllSketch sketch = sketchCache . get ( oldBuf ) . get ( oldPosition ) ; final WritableMemory oldMem = getMemory ( oldBuf ) . writableRegion ( oldPosition , size ) ; if ( sketch . isSameResource ( oldMem ) ) { // sketch has not moved final WritableMemory newMem = getMemory ( newBuf ) . writableRegion ( newPosition , size ) ; sketch = HllSketch . writableWrap ( newMem ) ; } putSketchIntoCache ( newBuf , newPosition , sketch ) ; }
In very rare cases sketches can exceed given memory request on - heap memory and move there . We need to identify such sketches and reuse the same objects as opposed to wrapping new memory regions .