I have a question concerning JNI:
JNIEXPORT jintArray JNICALL Java_MainClass_intArrayMethod
(JNIEnv *env, jobject obj, jintArray array) {
jintArray result;
jsize len = (*env)->GetArrayLength(env, array);
jint *body =(*env)->GetIntArrayElements(env, array, 0);
...
}
Can i do some loops and modify the values of body and then:
result = (*env)->NewIntArray(env, nb_of_subscribers*tags);
(*env)->SetIntArrayRegion(env, result, 0, tags*nb_of_subscribers, body);
(*env)->ReleaseIntArrayElements(env, array, body, 0);
In other words, can I modify the content of body
?
float *max = (float*)malloc(sizeof(float)*tags);
for(k=j;k<nb_of_subscribers*tags;k=k+tags)
if (body[k]>max[j%tags]) max[j%tags]=body[k];
for(k=0;k<nb_of_subscribers*tags;k=k+tags)
body[k]=(float)(body[k]/max[j%tags]);
the value of body doesn't change. how to override it?
can I modify the content of body?
Sure, but is that what you really want to do? You're returning a new array anyway, why modify the argument array as well?
body
are written back into the object when you call ReleaseIntArrayElements()
, as per the Javadoc - user207421 2012-04-06 09:58
The value of body is overwritten automatically without any restrictions.