I am new to JNI development. I am trying to simply just iterate or read value from direct byte buffer (LongBuffer) with JNI.
I first create a DirectByteBuffer as follows:
ByteBuffer buf = ByteBuffer.allocateDirect(5 * 8);
buf.putLong(12);
buf.putLong(4);
buf.putLong(9);
buf.putLong(7);
buf.putLong(8);
buf.rewind();
LongBuffer lBuf = buf.asLongBuffer();
// native method
long ret = this.quickSelect0(lBuf, 0, lBuf.remaining(), 2);
Native Code:
// using long* b/c we are using a LongBuffer
long* addr = (*env)->GetDirectBufferAddress(env, longBuffer);
printf ("\n1st element = %lu", addr[0]);
printf ("\n2nd element = %lu", addr[1]);
The output is some address instead of the values in the buffer:
1st element = 864691128455135232
2nd element = 288230376151711744
What am i missing?