in reply to Latest Strawberries: addresses reported by "p", Devel::Peek, etc.

You are seeing Copy-on-Write in action. In 5.32, the 's' x 32 expression is constant-folded at compile time, creating a hidden SV containing the 32-byte string. At run time this buffer is copied to $s. In 5.42, the copy is deferred: both $s and the hidden SV share the same PV buffer. When something happens to $s which looks like its buffer is going to be modified, then at that point the buffer is finally copied. pack 'p' is a wild-enough operation that perl assumes the worst, so does the copy before returning the (new) PC address.

The larger addresses are nothing to do with perl; they are just what the underlying OS and malloc() library supply.

Dave.

  • Comment on Re: Latest Strawberries: addresses reported by "p", Devel::Peek, etc.

Replies are listed 'Best First'.
Re^2: Latest Strawberries: addresses reported by "p", Devel::Peek, etc.
by Anonymous Monk on Oct 31, 2025 at 10:08 UTC

    Thanks for explanation. Looks like "'COW + p' leak by design now" to me, but maybe the case is too artificial for real life. I think pack has "You are responsible..." warning already.

    use strict; use Devel::Peek; $Devel::Peek::pv_limit = 3; # useless for UTF8 use warnings; use feature 'say'; say $^V; sub mem { say qx( tasklist /nh /fi "PID eq $$" ) =~ m[(\S+ K)$] } mem(); { my $r = \ join '', 'a' .. 'z'; $$r x= 1e7; my $s = $$r; my $p = pack 'p', $s; } mem(); { my $r = \ join '', 'a' .. 'z'; $$r x= 1e7; my $s = $$r; my $p = pack 'p', $s; } mem(); __END__ v5.32.1 7,836 K 7,888 K 7,888 K v5.42.0 8,036 K 261,972 K 515,880 K