in reply to Inline::C's AoA is much bigger than Perl's
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:
This took care of the size problem for the most part, and greatly improved the speed (though it's still slower than Perl).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 ); }
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:
With every iteration, the memory grows by at least 8kb.% perl test_aoa.pl 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)
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:
If anyone can spot the memory leak here, I'd much appreciate it!Attempt to free unreferenced scalar: SV 0x5b2c620, Perl interpreter: 0 +x603010 at test_aoa.pl line 22.
the lowliest monk
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Inline::C's AoA is much bigger than Perl's
by almut (Canon) on Mar 16, 2009 at 23:59 UTC | |
by ikegami (Patriarch) on Mar 17, 2009 at 01:26 UTC | |
by almut (Canon) on Mar 17, 2009 at 02:31 UTC |
In Section
Seekers of Perl Wisdom