Passing a byte[] in Java to a function in C through JNI: how to use jarraybyte

前端 未结 2 705
说谎
说谎 2020-12-13 13:50

This is the first time that I use the JNI and also the first time that I have to write some lines in C.

What I am trying to do is very simple. I\'m just trying to sw

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 14:41

    you can get jbyte* by GetByteArrayElements:

    jbyte* bufferPtr = (*env)->GetByteArrayElements(env, array, NULL);
    

    And it is important to know the length of your array:

    jsize lengthOfArray = (*env)->GetArrayLength(env, array);
    

    Having jbyte* and length, you can do all the things in c-array. Finally, releasing it:

    (*env)->ReleaseByteArrayElements(env, array, bufferPtr, 0);
    

提交回复
热议问题