JNI task using an array

Go To StackoverFlow.com


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);
if (body[k]>max[j%tags]) max[j%tags]=body[k];

the value of body doesn't change. how to override it?

2012-04-04 19:49
by holy


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?

2012-04-05 02:05
by user207421
please check my edited questio - holy 2012-04-05 05:52
@holy The revised values of 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.

2012-04-05 09:15
by holy