Other ideas to try.
Just push the pairs onto the stack and let the user assign that to a single level array:
my @diffs = diff( ... ); while( @diffs ) { my( $x, $y ) = ( pop @diffs, pop @diffs ); ## use em. }
Build a single level C array and return a SvPV that points to the head of that array:
U32 len = sizeof( U32 ) * some over estimate; U32 *diffs = malloc( len ); U32 i = 0; SV *packed; SvPV_Set( packed, diffs ); SvLEN_set( len ) for( ) { for( ) { diffs[ i++ ] = x; diffs[ i++ ] = y; { } SvCur_set( packed, ( i-1 ) * sizeof( U32 ) ); return packed; // sv_2mortal?
then use unpack to access the numbers:
my $diffs = diff( ... ); while( length( $diffs ) ) { my( $x, $y ) = unpack 'VV', substr( $diffs, 0, 8, '' ); ## use em. }
In reply to Re: Faster creation of Arrays in XS?
by BrowserUk
in thread Faster creation of Arrays in XS?
by wollmers
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |