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.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|