JNI - 带有ByteBuffer参数的本机方法

时间:2010-04-20 09:06:38

标签: java c java-native-interface bytebuffer

我有一个方法:

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实例)获取数据数组?

1 个答案:

答案 0 :(得分:30)

假设您使用ByteBuffer.allocateDirect()分配了ByteBuffer 你可以使用GetDirectBufferAddress

jbyte* bbuf_in;  jbyte* bbuf_out;

bbuf_in = (*env)->GetDirectBufferAddress(env, buf1);  
bbuf_out= (*env)->GetDirectBufferAddress(env, buf2);