in reply to Re^4: Bit vector fiddling with Inline C
in thread Bit vector fiddling with Inline C
I don't suppose your knowledge of the internals can confirm that the example in the OP is indeed just passing a pointer to $vector, and NOT copying the entire byte sequence somewhere else at the same time (even just as a side-effect)?
Yes. I can confirm that. No copying is done.
When you define an XS argument as SV* sv_vec, you are asking for a pointer to the SV. When you operate via that pointer, you are changing the original SV.
As with ordinary perl subs, the subroutines receives aliases to the actual variables passed:
sub x{ ++$_ for @_ };; ( $a, $b, $c) = 12345..12347;; x( $a, $b, $c );; print $a, $b, $c;; 12346 12347 12348
No copying occurs unless the programmer assigns them to local vars:
sub x{ my( $a, $b, $c ) = @_; ++$_ for $a, $b, $c; }
If I am defining perl subs to operate upon large scalars, and they are more complex than a couple of lines--at which point the $_[0], $_[1] nomenclature can become awkward--then I will use scalar refs:
sub xyz (\$) { my $rStr = shift; substr $$rStr, ...; vec $$rStr, ...; ... }
Which achieves the benefit of named variables without the cost of copying.
BTW: You still haven't mentioned what the "complex processing" you are performing in XS is?
I ask because my instinctual reaction that if you are performing boolean operations on whole pairs or more of large bit vectors, it is almost certainly quicker doing it in Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Bit vector fiddling with Inline C
by oxone (Friar) on May 09, 2011 at 21:54 UTC | |
by syphilis (Archbishop) on May 10, 2011 at 02:12 UTC | |
by BrowserUk (Patriarch) on May 10, 2011 at 07:06 UTC | |
by syphilis (Archbishop) on May 10, 2011 at 23:45 UTC | |
by BrowserUk (Patriarch) on May 11, 2011 at 01:01 UTC | |
| |
by oxone (Friar) on May 10, 2011 at 08:11 UTC | |
by BrowserUk (Patriarch) on May 10, 2011 at 14:34 UTC | |
by oxone (Friar) on May 10, 2011 at 05:56 UTC |