De : Shane Nay [mailto:[EMAIL PROTECTED]]
To comment on what John originally said..., arg, here we go. The
difference between print \$somevariable, and print $somevariable can
be very significant.
Nope. Not "very".
Everything is passed internally as a "reference", but that
doesn't me it's done in the same way. When you say "print $somevar",
and "print \$somevar" two VERY different things happen. case 1:
print $somevar (I'm assuming a type of string)
SV* somesv=(SV*)malloc(sizeof(SV));
somesv-sv_any=(void*)malloc(sizeof(char*)*strlen(ourstring));
//Notice, have to set aside memory
strcpy((char*)somesv-sv_any,ourstring); //Notice we have to copy our data
--Call the "print function" and pass it a reference to "somesv"
I'm sorry, but I think you are simply wrong here. If I call a perl
function or an XS routine with a variable as an argument it is passed by
reference. There is *no* copy.
A simple proof:
sub hack {
$_[0] = 'a new string';
}
$a = 'an old string';
hack $a;
print $a;
This part of your pseudo code:
SV* somesv=(SV*)malloc(sizeof(SV));
somesv-sv_any=(void*)malloc(sizeof(char*)*strlen(ourstring));
strcpy((char*)somesv-sv_any,ourstring); //Notice we have to copy our data
is *not* part of the call. It's the code that puts a value in "somesv",
i.e.
$somesv = "ourstring".
It is present in both the ref and the nonref cases.
Passing a refrence to $r-print is *slower*(by an infinitessimal amount).
The point of allowing it is to get around the problems with the normal
Perl coding style:
sub slow {
my $r = shift;
my $arg = shift; # A copy here!
$r-print ($arg);
}
But note the copy is not in the argument passing, it's in the Perl
code.
sub fast_but_ugly {
$_[0]-print ($_[1]);
}
--
John Hughes [EMAIL PROTECTED],
CalvaEDI SA.Tel: +33-1-4313-3131
66 rue du Moulin de la Pointe, Fax: +33-1-4313-3139
75013 PARIS.