JNI - native method with ByteBuffer parameter

左心房为你撑大大i 提交于 2019-11-28 20:24:51

问题


I've got a method:

public native void doSomething(ByteBuffer in, ByteBuffer out);

Generated by javah C/C++ header of this method is:

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) ?


回答1:


Assuming you allocated the ByteBuffer using ByteBuffer.allocateDirect() you can use GetDirectBufferAddress

jbyte* bbuf_in;  jbyte* bbuf_out;

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


来源:https://stackoverflow.com/questions/2673839/jni-native-method-with-bytebuffer-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!