我是JNI开发的新手。我试图简单地只使用JNI迭代或读取直接字节缓冲区(LongBuffer)中的值。
我首先创建一个DirectByteBuffer,如下所示:
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);
原生代码:
// 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]);
输出是一些地址而不是缓冲区中的值:
1st element = 864691128455135232
2nd element = 288230376151711744
我缺少什么?