Is it possible to simply reference the entire bytearray in JNI, but not reference any copy?
In native C code, I have a bytearray transitioning from Java, and I just want to compare some data with this bytearray, so I don't want to make any copy of the memory. Is it possible?
I know that I could get a pointer to a bytearray in native using GetPrimitiveArrayCritical, something like this
JNIEXPORT jbyteArray JNICALL Java_nfore_android_bt_pro_nfhfp_dsp (JNIEnv *env, jobject jobj, jbyteArray jbIn, jbyteArray jbBase){ jbyte *bufferIn; jbyte *bufferBase; bufferIn = (*env)->GetPrimitiveArrayCritical(env, jbIn, NULL); LOGD("Begin of dsp()"); LOGD("In dsp() Before Comparing..."); // Compare bufferIn with bufferBase here... LOGD("In dsp() After Comparing..."); LOGD("End of dsp()"); (*env)->ReleasePrimitiveArrayCritical(env, jbIn, bufferIn, 0); return jbIn; }
As you can see, because I can change the data in jbIn, I have to use GetPrimitiveArrayCritical to get its pointer and release it later.
However, if I just want to READ bytearray jbBase, how can I get a pointer to jbBase but not using GetPrimitiveArrayCritical?
Any suggestion will be appreciated. Thank you very much.
source share