我有一个方法:
public native void doSomething(ByteBuffer in, ByteBuffer out);
由javah生成此方法的C / C ++标题是:
JNIEXPORT void JNICALL Java__MyClass_doSomething (JNIEnv *, jobject, jobject, jobject, jint, jint);
如何从jobject(即ByteBuffer实例)获取数据数组?
答案 0 :(得分:30)
假设您使用ByteBuffer.allocateDirect()分配了ByteBuffer 你可以使用GetDirectBufferAddress
jbyte* bbuf_in; jbyte* bbuf_out;
bbuf_in = (*env)->GetDirectBufferAddress(env, buf1);
bbuf_out= (*env)->GetDirectBufferAddress(env, buf2);