Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

When should I use SetDoubleArrayRegion?

843829Nov 27 2005 — edited Dec 2 2005
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);
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 30 2005
Added on Nov 27 2005
2 comments
1,340 views