Get a ByteBuffer mapped to a portion of this memory. We keep a weak reference to all ByteBuffers provided so that this memory object is not GC'd while there are still implicit outstanding references to it (it'd be nice if we could attach our own reference to the ByteBuffer, but the VM generates the
(long offset, long length)
| 586 | * @return a direct ByteBuffer that accesses the memory being pointed to, |
| 587 | */ |
| 588 | @Override |
| 589 | public ByteBuffer getByteBuffer(long offset, long length) { |
| 590 | boundsCheck(offset, length); |
| 591 | ByteBuffer b = super.getByteBuffer(offset, length); |
| 592 | // Ensure this Memory object will not be GC'd (and its memory freed) |
| 593 | // if the Buffer is still extant. |
| 594 | buffers.put(b, this); |
| 595 | return b; |
| 596 | } |
| 597 | |
| 598 | @Override |
| 599 | public String getString(long offset, String encoding) { |