My advice is almost always the same when someone asks how to do something in XS code: Don't! Do it in Perl code where it is much easier to write, understand, debug, extend, etc. For example:

sub something { croak "Usage: ",__PACKAGE__,"::something( $a, $b, $c )" unless 3 == @_; my $cArray= pack( "d*", @_ ); _something( $cArray ); }
along with
void _something( cArray ) char * cArray; CODE: something( (double *)cArray );

There are actually ways to look through a Perl array and build this "packed", C-style array of doubles in XS code. They aren't horribly complicated in this specific case, but I don't know what they are because I don't really want to know because I find the Perl solution so much superior.

When writing XS code, I strive to make the XS interface minimal and very C-like and wrap that in Perl code that provides the rich interface that the module user will see.

I find that this approach leads to both more powerful and more efficient modules.

The one exception has been processing of SV buffers since you can't do these things portably in Perl code:

I've been considering writing an XS module that lets me do these things in Perl and then moving the buffer allocation code of my other XS modules out of XS and back into Perl because the complexity of the buffer allocation code is a problem since XS code is so hard to debug. ):

        - tye (but my friends call me "Tye")

In reply to (tye)Re: double array in XS by tye
in thread double array in XS by jettero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.