androidjava-native-interface

How to Convert the JNI jdoublearray to C's double* (pointer)


I am not much aware about JNI environment and stuck here. From Java layer to JNI, it is passing double[][] and double[] as an parameter, How can convert these into C's double*.

Any one have any suggestion?


Solution

  • I got it answer here:

    JNIEXPORT void JNICALL Java_JavaArrayTest
    (JNIEnv *env, jobject, jdoubleArray x, jdoubleArray y)
    { 
         long N        = env->GetArrayLength(x);           // Access the array length
    
         double* xPtr  = env->GetDoubleArrayElements(x,0); // Get C++ pointer to array data 
         double* yPtr  = env->GetDoubleArrayElements(y,0); // and "pin" array elements
    
         - - - - - -
    }
    

    Where O/1 defined as :

    #define JNI_FALSE 0
    #define JNI_TRUE 1