in reply to Passing a very large string by reference to a c library

Maybe example 4 of the XStutorial can help you on - it looks good but I've never really done anything in XS before...

-- Hofmator

  • Comment on Re: Passing a very large string by reference to a c library

Replies are listed 'Best First'.
Re: Re: Passing a very large string by reference to a c library
by dino (Sexton) on Jul 12, 2001 at 17:19 UTC
    Thks,

    This is what I've been looking at. The example doesn't use references, though example 6 does. I can try to meld both together so that I can call:

    find_index($key, \$data);

    I guess a lot depends on how SvPV works. If it copies the data then I need another method.

    dino

      I've got it to work with:

      unsigned long
      find_index (key, data)
              unsigned long         key
              SV    *               data
          INIT:
             STRLEN          datalen;
             char * s;
             if ((!SvROK(data))
                || (SvTYPE(SvRV(data)) != SVt_PV))
             {
                XSRETURN_UNDEF;
             }
             s = SvPV(SvRV(data), datalen);
          CODE:
            RETVAL = find_index (key, s, datalen);
          OUTPUT:
            RETVAL
      

      I'm still not sure if SvPV copies its internal data somewhere or just returns a pointer to it.

      Comments please

      dino

        And finally,

        from the perlapi manpage:

         SvPV    Returns a pointer to the string in the SV, or a
                 stringified form of the SV if the SV does not con-
                 tain a string.  Handles 'get' magic.
         
                 char*   SvPV(SV* sv, STRLEN len)
        

        so that should do it

        dino