title: How to read a bytearray in JNI?
body: <p>Is it possible to just reference a entire bytearray in JNI but not invoking any copy ?</p>
  
  <p>In native C code, I have a bytearray passing from Java, and I just want to compare some data to this bytearray so I do not want to do any memory copy. Is it possible ?</p>
  
  <p>I know I could get the pointer of a bytearray in native by using GetPrimitiveArrayCritical something like that </p>
  
  <pre><code>JNIEXPORT jbyteArray JNICALL Java_nfore_android_bt_pro_nfhfp_dsp
  (JNIEnv *env, jobject jobj, jbyteArray jbIn, jbyteArray jbBase){
  
      jbyte *bufferIn;
      jbyte *bufferBase;
      bufferIn = (*env)-&gt;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)-&gt;ReleasePrimitiveArrayCritical(env, jbIn, bufferIn, 0);
  
      return jbIn;
  }
  </code></pre>
  
  <p>As you could see, because I might change the data in the jbIn, I should use GetPrimitiveArrayCritical to get its pointer and release it later.</p>
  
  <p>However, if I just want to READ the bytearray jbBase, how could I get the pointer of the jbBase but not using GetPrimitiveArrayCritical ?</p>
  
  <p>Any suggestion would be appreciated. Thanks a lot.</p>