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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |