javac++java-native-interfacejniwrapper

How to convert C++ Array<float,size> to jfloatArray in JNIWrapper?


I want to map my C++ array output to jniFloatArray.

Tried to follow this solution:

"Convert float* to jfloatArray using JNI"

but I am unable to point float* to array object.

Let's say my output in C++ array output object is:

output = {1.0f ,2.0f ,3.0f};

What I really want is to convert or map this output (array) to jfloatArray in JniWrapper.


Solution

  • @Michael solved the problem. So by using output.data() and setting float pointer to it as:

    float *ptr = output.data();
    

    solved the issue.