Hi Gregg,
Gregg Allen schrieb:
I am totally new to this list, and I need someone's help.
I have some code written in C which takes an array of arbitrary values,
a desired percentile, and returns the desired percentile.
I also have the descriptive statistics module, in a Perl program that I
have running 24/7. It spends most of it's time getting the requested
percentile.
(In comparison, the median XS program is hundreds of times faster.)
So what's the correct way to have a Perl program pass some "@array" to
an inline C program, do its voodoo, and return the value at the
percentile value I requested?
Don't worry about helping me with the percentile program in C, I've got
that part handled. (Unless I have to change it for the inline stuff.)
I had a similar issue recently when writing Math::FFTW. (It's XS, not
Inline::C, but the differences are almost nil.)
What I needed was a double* array on the C/XS side and wanted to pass in
an array reference. You can copy the code in Math::FFTW almost verbatime
for that.
The one difference is most likely going to be that you do not want to
build the whole double array but iterate over the Perl array. Be aware
that the XS array length function/macro doesn't return the length but
the index of the last element.
There are other approaches, though: use "pack" on the Perl side to pack
the data into a double* and pass that to the XS code in an SV *. Then
basically just cast the binary string into a (double *) using some form
of SvPV_nolen or so.
Another approach is to achieve the same thing as pack using
Convert::Binary::C. But that's probably a bit heavy handed here.
Steffen