[foreign] Pointer to fixed-size array: is jexctract's mapping to Java correct?

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Feb 27 21:37:23 UTC 2019


On 27/02/2019 21:18, Maurizio Cimadamore wrote:
> int N = 200; //number of complex pairs
> try (Scope s = Scope.globalScope().fork()) {
>    Array<Array<Double>> pairs = 
> s.allocateArray(NativeTypes.DOUBLE.array(2), N);
>    for (int i = 0 ; i < N ; i++) {
>        pairs.set(i, s.allocateArray(NativeTypes.DOUBLE, new double[] { 
> d1, d2 }); // replace d1 and d2 with actual data
>    }
>
>    ...
>
>    Pointer<Array<Double>> pairs_ptr = pairs.elementPointer();
>
> }
>
>
> Am I right that your discomfort comes from having to allocate all 
> those native arrays? (which will then copied in the destination pair 
> array)

And, more to the point, let's assume the API was defined differently, e.g.

typedef struct fftw_complex { double real; double img; }


Would you be surprised if jextract generated an API that said 
Pointer<fftw_complex> ? I have a suspicion that you might be less 
surprised by that choice, but in reality what would happen would be the 
same - and to allocate something you can pass to the API you would still 
do something very very similar to the code I've shown earlier - with the 
only difference that, instead of allocating an array in the loop, you 
would be allocating a struct (and then you'd have to set the struct fields).

Am I completely off track?


Maurizio




More information about the panama-dev mailing list