Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

Update:Actually the problems with the code below, I just discovered, are far more serious than a mere memory leak. It blows up if I try to accesses the elements in the table... I guess it's time for me to call it a day!

OK, I'm replying to myself here...

After I posted the original query, I tried a different tack. I streamlined the C function make_aoa_c, as follows:

SV *make_aoa_c( int n_rows, int n_cols ) { int i, j; char *foo = "foo"; AV *table = newAV(); AV *row; for ( i = 0; i < n_rows; ++i ) { row = ( AV * ) sv_2mortal( ( SV * ) newAV() ); for ( j = 0; j < n_cols; ++j ) { av_push( row, newSVpv( foo, 0 ) ); } av_push( table, sv_2mortal( newRV( ( SV * ) row ) ) ); } return newRV( ( SV * ) table ); }
This took care of the size problem for the most part, and greatly improved the speed (though it's still slower than Perl).

Unfortunately, the code has sprung a small memory leak that I can't identify! Changing the number of repetitions to 10, now the output for the C case looks like this:

% perl 1 1: 78844 (280041 us) 2: 78884 (247865 us) 3: 78892 (237725 us) 4: 78900 (245755 us) 5: 78908 (235251 us) 6: 78916 (235712 us) 7: 78924 (246926 us) 8: 78932 (237128 us) 9: 78940 (237369 us) 10: 78948 (238528 us)
With every iteration, the memory grows by at least 8kb.

I have tried adding sv_2mortal around various items in the code (e.g. AV *table=(AV *)sv_2mortal((SV *)newAV())), but I get errors like:

Attempt to free unreferenced scalar: SV 0x5b2c620, Perl interpreter: 0 +x603010 at line 22.
If anyone can spot the memory leak here, I'd much appreciate it!

the lowliest monk

In reply to Re: Inline::C's AoA is much bigger than Perl's by tlm
in thread Inline::C's AoA is much bigger than Perl's by tlm

and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (6)
    As of 2014-12-28 22:30 GMT
    Find Nodes?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?

      Results (183 votes), past polls