note
kyle
<p><i>(perl subs use call-by-value, which makes a copy)</i>
<p>I don't think this is true.
<C>
report_mem( 'program start' );
my $big = 'x' x 100_000_000;
report_mem( 'after making big string' );
take_big_arg( $big );
sub take_big_arg {
printf "got %d characters\n", length $_[0];
report_mem( 'passed to function' );
}
sub report_mem {
my ( $msg ) = @_;
printf "%d %s\n", my_mem(), $msg;
}
sub my_mem {
my ($proc_info)
= grep { $_->[2] == $$ } map { [ split ] } `ps l | tail -n +2`;
return $proc_info->[6];
}
__END__
13124 program start
208444 after making big string
got 100000000 characters
208444 passed to function
</c>
<p>The truth is Perl gives the sub aliases to the variables you pass. Common practice is to copy them after that (<c>my ($copy) = @_</c>), but that's something else.
655381
655390