@Override public byte readByte(int offset) { assert offset < getDataSize(); return UnsafeMemoryChunk.readAbsoluteByte(getBaseDataAddress() + offset); }
@Override public void readBytes(int offset, byte[] bytes, int bytesOffset, int size) { assert offset+size <= getDataSize(); UnsafeMemoryChunk.readAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size); }
@Override public void writeByte(int offset, byte value) { assert offset < getDataSize(); UnsafeMemoryChunk.writeAbsoluteByte(getBaseDataAddress() + offset, value); }
@Override public void writeBytes(int offset, byte[] bytes, int bytesOffset, int size) { assert offset+size <= getDataSize(); UnsafeMemoryChunk.writeAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size); }
/** * Creates and returns a direct ByteBuffer that contains the contents of this Chunk. * Note that the returned ByteBuffer has a reference to this chunk's * off-heap address so it can only be used while this Chunk is retained. * @return the created direct byte buffer or null if it could not be created. */ @Unretained public ByteBuffer createDirectByteBuffer() { return basicCreateDirectByteBuffer(getBaseDataAddress(), getDataSize()); } @Override
/** * Returns an address that can be used with unsafe apis to access this chunks memory. * @param offset the offset from this chunk's first byte of the byte the returned address should point to. Must be >= 0. * @param size the number of bytes that will be read using the returned address. Assertion will use this to verify that all the memory accessed belongs to this chunk. Must be > 0. * @return a memory address that can be used with unsafe apis */ public long getUnsafeAddress(int offset, int size) { assert offset >= 0 && offset + size <= getDataSize(): "Offset=" + offset + ",size=" + size + ",dataSize=" + getDataSize() + ", chunkSize=" + getSize() + ", but offset + size must be <= " + getDataSize(); assert size > 0; long result = getBaseDataAddress() + offset; // validateAddressAndSizeWithinSlab(result, size); return result; }