int com(constvoid *a, constvoid *b){
return *(int *)a - *(int *)b;//升序
}
JNIEXPORT void JNICALL Java_com_test_git_jnidemo_JniUtil_JniDemo_passArrayMethod
(JNIEnv *env, jobject jobj, jintArray jarr){
//1.获取数组指针
jint *arr = env->GetIntArrayElements(jarr, NULL);
*arr = 100;
//2.获取数组长度int len = env->GetArrayLength(jarr);
//3.排序
qsort(arr, len, sizeof(jint), com);
//4.释放资源
env->ReleaseIntArrayElements(jarr, arr, JNI_COMMIT);
// env->ReleaseIntArrayElements(jarr, arr, JNI_ABORT);// 对于最后一个参数(如果指针指向的数组为副本时,否则该参数不起作用)// 0 copy back the content and free the elems buffer// JNI_COMMIT copy back the content but do not free the elems buffer// JNI_ABORT free the buffer without copying back the possible changes
};