Java JNI - 带有 ByteBuffer 参数的本机方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2673839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JNI - native method with ByteBuffer parameter
提问by Arek
I've got a method:
我有一个方法:
public native void doSomething(ByteBuffer in, ByteBuffer out);
Generated by javah C/C++ header of this method is:
这个方法的javah C/C++头文件生成的是:
JNIEXPORT void JNICALL Java__MyClass_doSomething (JNIEnv *, jobject, jobject, jobject, jint, jint);
How can I get a data array from jobject (that is a ByteBuffer instance) ?
如何从 jobject(即 ByteBuffer 实例)获取数据数组?
采纳答案by stacker
Assuming you allocated the ByteBuffer using ByteBuffer.allocateDirect() you can use GetDirectBufferAddress
假设您使用 ByteBuffer.allocateDirect() 分配了 ByteBuffer,您可以使用GetDirectBufferAddress
jbyte* bbuf_in; jbyte* bbuf_out;
bbuf_in = (*env)->GetDirectBufferAddress(env, buf1);
bbuf_out= (*env)->GetDirectBufferAddress(env, buf2);