Java arrays to C pointers

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Java arrays to C pointers

Guillaume Bittoun

Hi everyone,

I am having hard time understanding how I can pass java arrays to my C++ code using SWIG. The java code I would like to use is the following :

float[] foo = someProcessingFunction(…)

myCppFunction(foo)

So that the prototype `myCppFunction` in my C++ code would be either,

myCppFunction(float * floatArray)

or,

myCppFunction(float * floatArray size_t length)

So far, all my attempts have failed, I thought there would be something like the `char * STRING` and`char * BYTE` typemaps that can maps `byte[]` to `String` or `char*` but I still cannot find anything about mapping float arrays.

There is either something obvious I missed or maybe a typemap to create but I cannot find any solution so far. Is there a way to map java’s `float[]` to C++ `float *` ? Moreover, is there a way to return a java `float[]` using a C++ function wrapped by swig ?

Help is welcome.

Regards,

Guillaume


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: Java arrays to C pointers

Guillaume Bittoun

EDIT: I just realized that it is possible to use jfloatArray both as input and output parameters. This is an obvious thing I missed, if there is any other best practice on this point, don’t hesitate to tell me.

Regards,

Guillaume


On 21/04/17 11:52, Guillaume Bittoun wrote:

Hi everyone,

I am having hard time understanding how I can pass java arrays to my C++ code using SWIG. The java code I would like to use is the following :

float[] foo = someProcessingFunction(…)

myCppFunction(foo)

So that the prototype `myCppFunction` in my C++ code would be either,

myCppFunction(float * floatArray)

or,

myCppFunction(float * floatArray size_t length)

So far, all my attempts have failed, I thought there would be something like the `char * STRING` and`char * BYTE` typemaps that can maps `byte[]` to `String` or `char*` but I still cannot find anything about mapping float arrays.

There is either something obvious I missed or maybe a typemap to create but I cannot find any solution so far. Is there a way to map java’s `float[]` to C++ `float *` ? Moreover, is there a way to return a java `float[]` using a C++ function wrapped by swig ?

Help is welcome.

Regards,

Guillaume



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: Java arrays to C pointers

William S Fulton
William

On 21 April 2017 at 12:07, Guillaume Bittoun <[hidden email]> wrote:

EDIT: I just realized that it is possible to use jfloatArray both as input and output parameters. This is an obvious thing I missed, if there is any other best practice on this point, don’t hesitate to tell me.

Regards,

Guillaume


On 21/04/17 11:52, Guillaume Bittoun wrote:

Hi everyone,

I am having hard time understanding how I can pass java arrays to my C++ code using SWIG. The java code I would like to use is the following :

float[] foo = someProcessingFunction(…)

myCppFunction(foo)

So that the prototype `myCppFunction` in my C++ code would be either,

myCppFunction(float * floatArray)

or,

myCppFunction(float * floatArray size_t length)

So far, all my attempts have failed, I thought there would be something like the `char * STRING` and`char * BYTE` typemaps that can maps `byte[]` to `String` or `char*` but I still cannot find anything about mapping float arrays.

There is either something obvious I missed or maybe a typemap to create but I cannot find any solution so far. Is there a way to map java’s `float[]` to C++ `float *` ? Moreover, is there a way to return a java `float[]` using a C++ function wrapped by swig ?

Help is welcome.

Regards,

Guillaume



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: Java arrays to C pointers

Guillaume Bittoun

Thanks,

FYI, there is another option that I’ve chosen : adding the `JEnv * jniEnv` variable in the C++ functions prototype and ignore it in the typemap using the following code in the interface file :

%typemap(in, numinputs=0) JNIEnv *jenv %{
   $1 = jenv;
%}

I think that this isn’t obviously the best choice but it might help some of you. In any case, first try the arrays_java.i as William told me :-)

Regards, and sorry for the late answer (I solved this a month ago).

Guillaume


On 21/04/17 19:45, William S Fulton wrote:
William

On 21 April 2017 at 12:07, Guillaume Bittoun <[hidden email]> wrote:

EDIT: I just realized that it is possible to use jfloatArray both as input and output parameters. This is an obvious thing I missed, if there is any other best practice on this point, don’t hesitate to tell me.

Regards,

Guillaume


On 21/04/17 11:52, Guillaume Bittoun wrote:

Hi everyone,

I am having hard time understanding how I can pass java arrays to my C++ code using SWIG. The java code I would like to use is the following :

float[] foo = someProcessingFunction(…)

myCppFunction(foo)

So that the prototype `myCppFunction` in my C++ code would be either,

myCppFunction(float * floatArray)

or,

myCppFunction(float * floatArray size_t length)

So far, all my attempts have failed, I thought there would be something like the `char * STRING` and`char * BYTE` typemaps that can maps `byte[]` to `String` or `char*` but I still cannot find anything about mapping float arrays.

There is either something obvious I missed or maybe a typemap to create but I cannot find any solution so far. Is there a way to map java’s `float[]` to C++ `float *` ? Moreover, is there a way to return a java `float[]` using a C++ function wrapped by swig ?

Help is welcome.

Regards,

Guillaume



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user