pdupre has asked for the wisdom of the Perl Monks concerning the following question:

I need to call a c subroutine from perl. I have an array of array that I need to pass to the c routine (ie. a double** or [] []). Which typemap should I put in the xs file ? Thank.

Replies are listed 'Best First'.
Re: double **
by samtregar (Abbot) on Jul 02, 2008 at 21:15 UTC
    There isn't one. You've got a couple options that I know of. First, you could write pull the NVs out of your AVs and put them into a new double [][] that you New() and Safefree() on the spot. That will use lots of memory if your array is big. Alternately you could have your Perl code keep your data in packed C arrays to begin with, using something like Tie::CArray. Then you can write a little XS to put out the double** from that and pass it to your C code.

    -sam

      Hello Sam, thank for your email. SO my conclusion is that it is going to be efficient to call a c routine with a AoA, I imagined that the machine representation was close between a AoA and a double [][]! It looks like that I am wrong. Will it it be a lot more efficient to pass several double [] ? Regards. Patrick Dupre The University of York
        Yup, AVs and C arrays are very different beasts. If the volume of data is the same I don't think you'll see a big difference between a double[][] and several double[]s but only you know the details well enough to judge.

        -sam