using TinyPerl 5.8 under Windows XP

Tinyperl is not fully perl: it doesn't even come with Devel::Peek, which has been core since 5.6, before tinyperl 5.8.0 was released. (I found this out when I vainly tried to use your own favorite pseudo-perl to run ikegami's example, and couldn't, because it didn't have that essential part of core.)

When I use Strawberry Perl 5.8.8 (which comes with all of core), it gets essentially the same results that ikegami already showed: if you use the subroutine's argument directly, rather than making a copy of the string, then Perl doesn't copy the string.

why is it that as soon as I do my $STRING = shift; inside my sub, Perl's memory usage doubles

You do realize that you just essentially asked, "why is it that as soon as I make a copy of the string inside my sub, Perl makes a copy of the string?" Do you understand how silly it sounds when rephrased that way?

Perl 5.8 doesn't have the fancy v5.20 Copy-on-Write ("COW") feature that ikegami mentioned (so the scalar of the copied version doesn't point to the same string buffer), but it does pass the subroutine arguments by reference (so the scalar is the same outside and inside of f($x) ). However, as soon as you make a copy of a string passed by reference, you no longer are using that reference, but a copy of the string -- hence, without COW, the memory goes up when you make the copy , but not when you called the sub . If, like ikegami, you stick to always using the $_[0] rather than creating a copy, it would not double your memory even in tinyperl.

update: rephrased a few things, but essentially meaning has stayed the same

update 2: too harsh in some of my wording, especially the struck out -- sorry.


In reply to Re^4: Passing argument by reference (for a scalar) by pryrt
in thread Passing argument by reference (for a scalar) by jmClifford

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.