我想传递一个简单的java数组到c。传递简单的java数组到原始的c数组swig
现在我用下面的.i文件来做。
%module example
%include "arrays_java.i"
%include "example.h"
%{
#include "example.h"
%}
与arrays_java.i标头java数组被接受。 但它使数组的完整副本,这对我来说很慢。 我试图用这些构建一个typemap,我可以使用GetDoubleArray函数来获取java数组的指针。 在我使用swig之前,我使用JNI GetDoubleArrayElements构建了自己的包装,而且速度更快。
下面您可以看到我尝试在类型映射中使用Jni函数。
%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) };
但痛饮建立我只是一个javaclass(SWIGTYPE_p_double),我应该使用。 我只想传递一个简单的java数组,并在c中使用这个java数组指针。
希望你能帮助我THX
编辑:
在这里你可以看到我的完整.i文件。我纠正了长久的失败。同样的问题
%module exampleModule
%include "std_string.i"
%include "std_vector.i"
%include "arrays_java.i"
#include <string>
#include <vector>
%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's just grab the original header file here */
%include "example.h"
%{
#include "example"
%}
和.h文件
class example
{
public:
example(int width, int height);
~example();
test(double *values, int length);
};
是我能看到-Wall输出?我尝试它,但我成为没有输出在Android工作室终端
看起来像拼写单词“length”时出现拼写错误,但也存在更多问题。使用-Wall参数运行SWIG,并记下我很确定您会在'%apply'上看到的警告。你可以向我们展示example.h和包含你的类型映射的.i文件吗? – Flexo
我编辑了我的帖子。 thx回答 –