Pass, return and convert to vectors list of lists over JNI

前端 未结 4 2155
广开言路
广开言路 2020-12-28 14:41

I need to pass from Java

List< List > points;

over jni to C++ and convert to

std::vector< std::vec         


        
4条回答
  •  -上瘾入骨i
    2020-12-28 15:14

    As i understand it from the reference the JNI, JNI can only work with one-dimensional arrays of primitive types or objects.

    Because on the side of Java, had to translate the list into an array. Then, in the native part the array passed and the number of elements. There's going to the desired vector and processed. Returns as a result of two arrays (array with points all contours and the array with the number of points in each contour) and the number of contours. The resulting array is collected in a list of lists on the side of Java.

    While the problem is not solved completely, because the JNI can not allocate memory for an existing item in the native part. Therefore it is necessary to extract the data in part, to allocate memory for them on the side of Java, and fill in the native.

    A possible resolve may be the use of binders such as SWIG or JavaCpp

提交回复
热议问题