Hi,
I am writing some wrappers for calling a C library from Java.
In the example below, I pass in arr (an array of double values) and the library puts the sine of the values into array ans.
Java creates both arrays before the call.
To get the result out of temporary storage resand back into ans, everything I read about JNI suggested I needed the line:
(*env)->SetDoubleArrayRegion(env, ans, 0, len, res);
but I noticed that if I comment it out, it seems to work just as well!
Can anyone please explain why this works and what the SetDoubleArrayRegion is meant to be used for?
Thanks
Roger
Here is the code:
JNIEXPORT void JNICALL Java_ch_actuary_util_maths_FastMaths_sinArray_1c
(JNIEnv *env, jclass obj, jdoubleArray arr, jdoubleArray ans)
{
double *data, *res;
jsize len = (*env)->GetArrayLength(env, arr);
data = (*env)->GetDoubleArrayElements(env, arr, 0);
res = (*env)->GetDoubleArrayElements(env, ans, 0);
vdSin(len, data, res); // call to library function
// (*env)->SetDoubleArrayRegion(env, ans, 0, len, res);
(*env)->ReleaseDoubleArrayElements(env, arr, data, 0);
(*env)->ReleaseDoubleArrayElements(env, ans, res, 0);
}