Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
For the method shown here, I doubt it would make much difference, and if it did, it'd probably be to slow it down rather than speed it up. If you're going to write things in C to speed them up, then it helps to have the data in C structures and access it there. Otherwise you might as well just use perl instead of introducing additional access layers.

Still, I could be wrong since the slowest part of perl is calling a sub. If you called your C function the hundreds of thousands of times from the C code (rather than from perl), it could possibly speed it up.

UPDATE: also, I've completed my assignment. I hope I get an A on my homework. (In all seriousness, I've never tried Inline::C before. Normally I don't write complete solutions...)

BTW, the secret to figuring this stuff out is: you can't. It's really really arcane. But these pages can help: perlxs, perlapi, perlguts, perlxstut, perlclib, and perlcall. I used perlxs, perlapi, perlguts, and some source I had written before to figure this out. It can also help to browse the source of perl itself.

#!/usr/bin/perl use strict; use Inline 'C'; use Data::Dumper; my $hash = { parent => { parent => {} } }; root($hash); print "", Dumper({initial=>$hash, result=>root($hash)}), "\n"; __END__ __C__ SV* root(SV* sv) { if( SvOK(sv) && SvTYPE(sv) == SVt_RV ) { HV* h = SvRV(sv); SV* r; int i = 0; while( hv_exists(h, "parent", 6) ) { r = *( hv_fetch(h, "parent", 6, 0) ); if( SvOK(r) && SvTYPE(r) == SVt_RV ) { h = SvRV(r); i = 1; } } if( i ) { SvREFCNT_inc(r); return r; } } else { croak("please pass hash refs to root"); } return &PL_sv_undef; }

-Paul


In reply to Re: Inline::C hash access by jettero
in thread Inline::C hash access by fireartist

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (5)
    As of 2021-04-20 13:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?