One thing you'll need to look for is places where a scalar's internal type might change. For example:

my $number = 10; print "$number\n";

That second line is going to actually write to $number by changing it from a pure integer (IV) into a string/integer (PVIV). You can prove this by using Devel::Peek:

use Devel::Peek; my $number = 10; Dump($number); print "Number is $number\n"; Dump($number);

Which outputs:

SV = IV(0x9a5cfe0) at 0x9a41774 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,pIOK) IV = 10 Number is 10 SV = PVIV(0x9a42b10) at 0x9a41774 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,POK,pIOK,pPOK) IV = 10 PV = 0x9a57758 "10"\0 CUR = 2 LEN = 4

If that variable was part of your shared pre-fork data then that data page just got unshared, all 4k of it! It's possible to avoid this in some cases, for example by using printf() instead of print() above, but it's quite difficult to find all the possible cases.

To learn more about how Perl manages memory check out perlguts.

-sam


In reply to Re: fork(): where does copy happen? by samtregar
in thread fork(): where does copy happen? by Anonymous Monk

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.