in reply to XS: Converting a data structure in a string

I'm not an expert on this at all, but wouldn't you be better off using Inline::C (especially as you're just starting out)? Looks like a considerably lower entry barrier for interbreeding C and perl.


Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
  • Comment on Re: XS: Converting a data structure in a string

Replies are listed 'Best First'.
Re^2: XS: Converting a data structure in a string
by creamygoodness (Curate) on Nov 04, 2005 at 17:07 UTC
    I'm not sure this algo is a good candidate for either XS or Inline::C. It's not computationally intensive. There might be a small boost in performance from going to XS, but unless this particular sub has been identified as a bottleneck during profiling and you need to squeeze every last CPU cycle out of it, I'd leave it in Perl.
    --
    Marvin Humphrey
    Rectangular Research ― http://www.rectangular.com

      Agreed. I was under the impression the OP was trying to dip his toes into mixing C with perl code, and personally the only approach to that which doesn't send me slinking away shamefully is with Inline::C ;-)


      Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan

        I started out with Inline::C, too. The hard part is establishing proficiency with a sufficent number of perlapi macros. Once you have that down, the leap from Inline::C to XS is pretty small.

        --
        Marvin Humphrey
        Rectangular Research ― http://www.rectangular.com
      Thanks for your suggestion.

      This function is already implemented at perl level, and for historical reasons (read: legacy code) it handles Big™ data structures, resulting in 10/15 Mb strings.

      And yes, this function has been selected as good candidate for XS/ Inline::C rewriting through basic profiling.

      I thought it might be a valid experiment to learn XS. Probably I should discard Inline::C as a viable alternative because of internal distribution and servers update issues. Nevertheless I'm going to study Inline::C some more...