in reply to Faster creation of Arrays in XS?
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. }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Faster creation of Arrays in XS?
by wollmers (Scribe) on Jun 22, 2015 at 09:36 UTC | |
by BrowserUk (Patriarch) on Jun 22, 2015 at 11:02 UTC | |
by wollmers (Scribe) on Jun 22, 2015 at 11:52 UTC | |
by BrowserUk (Patriarch) on Jun 22, 2015 at 12:45 UTC | |
by wollmers (Scribe) on Jun 22, 2015 at 14:49 UTC | |
| |
by BrowserUk (Patriarch) on Jun 22, 2015 at 14:09 UTC |