I want to pass a simple java array to c.
I am currently doing this with the following .i file.
%module example
%include "arrays_java.i"
%include "example.h"
%{
#include "example.h"
%}
with arrays of headers arrays_java.i was accepted. But it makes a full copy of the array, and it slows me down. I tried to create a sample map using these functions, I can use the GetDoubleArray function to get a pointer to a java array. Before using swig, I create my own wrapper using JNI GetDoubleArrayElements, and it was much faster.
Below you can see my attempt to use Jni functions in a map.
%typemap(jtype) (double *values, int lenght) "double[]"
%typemap(jstype) (double *values, int lenght) "double[]"
%typemap(javain) (double *values, int lenght) "$javainput"
%typemap(jni) (double *values, int lenght) "jdoubleArray"
%typemap(in) (double *values, int lenght) {
$1 = (double *)JCALL2(GetDoubleArrayElements, jenv, $input, NULL);
$2 = (int) JCALL1(GetArrayLength, jenv, $input);
}
%apply (double * DOUBLE, int LENGTH) { (double * doubleArray, long len) };
But swig only creates me javaclass (SWIGTYPE_p_double) which I should use. I just want to pass a simple java array and use this java array pointer in c.
hope you can help me thanks
EDIT:
.i. .
%module exampleModule
%include "std_string.i"
%include "std_vector.i"
%include "arrays_java.i"
%template(nativeDoubleVector) std::vector<double>;
%typemap(jtype) (double *values, int length) "double[]"
%typemap(jstype) (double *values, int length) "double[]"
%typemap(javain) (double *values, int length) "$javainput"
%typemap(jni) (double *values, int length) "jdoubleArray"
%typemap(in) (double *values, int length) {
$1 = (double *)JCALL2(GetDoubleArrayElements, jenv, $input, NULL);
$2 = (int) JCALL1(GetArrayLength, jenv, $input);
}
%apply (double * values, int length) { (double * doubleArray, long len) };
/* Let just grab the original header file here */
%include "example.h"
%{
%}
.h
class example
{
public:
example(int width, int height);
~example();
test(double *values, int length);
};
-Wall? , android studio