java - How to return double[] in jni input argument -


in java code have defined following function signature:

public native boolean getdata( double [] data ); 

in c++ code i'd populate double array data return java, , returned boolean function indicate whether data set correctly or not.

javah created following c++ function signature:

jniexport jboolean jnicall java_com_test_getdata___3d( jnienv* penv, jclass cls, jdoublearray darray )  

how implement function in c++ can return 3 double values generated in c++ code?

i'd similar article: http://www.javaworld.com/article/2077554/learn-java/java-tip-54--returning-data-in-reference-arguments-via-jni.html instead of using stringbuffer, i'd fill in array of doubles values.

it should follows:

jniexport jboolean jnicall java_com_test_getdata___3d( jnienv* penv, jclass cls, jdoublearray darray ) {     jboolean iscopy1;     jdouble* srcarrayelems =             penv->getdoublearrayelements(darray, &iscopy1);     jint n = penv->getarraylength(darray);     jboolean res = false;      // here update srcarrayelems values, maybe set res true      if (iscopy1 == jni_true) {        penv->releasedoublearrayelements(darray, srcarrayelems, jni_abort);     }     return res ; } 

when calling getdata array must allocated - means of correct length.

i have not compiled code, can find lots of samples on google, here links:

http://www.ict.nsc.ru/win/docs/java/tutorial/native1.1/implementing/array.html http://statweb.stanford.edu/~naras/java/course/lec5/lec5.html


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -