in reply to Re: perl5.10 Devel::Size behaviour changed?
in thread perl5.10 Devel::Size behaviour changed?

I couldn't leave it at that. It seems that Devel::Size actually modifies the array!
>perl -MDevel::Size=total_size -MDevel::Peek -e"my @a; total_size(\@a) + if $ARGV[0]; Dump \@a,1" 0 SV = RV(0x239ba8) at 0x239b9c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x1829954 SV = PVAV(0x23aa60) at 0x1829954 REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) >perl -MDevel::Size=total_size -MDevel::Peek -e"my @a; total_size(\@a) + if $ARGV[0]; Dump \@a,1" 1 SV = RV(0x239ba8) at 0x239b9c REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x1829954 SV = PVAV(0x23aa60) at 0x1829954 REFCNT = 2 FLAGS = (PADMY,RMG) MAGIC = 0x1824014 MG_VIRTUAL = &PL_vtbl_arylen_p MG_TYPE = PERL_MAGIC_arylen_p(@) MG_FLAGS = 0x02 REFCOUNTED ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL)

It's similar but different than using $#a:

>perl -MDevel::Size=total_size -MDevel::Peek -e"my @a; $#a if $ARGV[0] +; Dump \@a,1" 0 SV = RV(0x239260) at 0x239254 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x182991c SV = PVAV(0x23a168) at 0x182991c REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) >perl -MDevel::Size=total_size -MDevel::Peek -e"my @a; $#a if $ARGV[0] +; Dump \@a,1" 1 SV = RV(0x239340) at 0x239334 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x182991c SV = PVAV(0x23a168) at 0x182991c REFCNT = 2 FLAGS = (PADMY,RMG) MAGIC = 0x1823de4 MG_VIRTUAL = &PL_vtbl_arylen_p MG_TYPE = PERL_MAGIC_arylen_p(@) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x239254 SV = PVMG(0x18fb364) at 0x239254 REFCNT = 1 FLAGS = (GMG,SMG) IV = 0 NV = 0 PV = 0 MAGIC = 0x1823f0c MG_VIRTUAL = &PL_vtbl_arylen MG_TYPE = PERL_MAGIC_arylen(#) MG_OBJ = 0x182991c ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x239254 FLAGS = (REAL)

Replies are listed 'Best First'.
Re^3: perl5.10 Devel::Size behaviour changed? (bug report)
by ikegami (Patriarch) on Sep 04, 2009 at 17:56 UTC

      If it's a bug, it's not attributable to Devel::Size. Any operation that queries the size does the same thing:

      perl -MDevel::Peek -e "my @a; Dump \@a, 1; printf qq[SIZE :%d\n], $#a; + Dump \@a, 1" SV = RV(0x34e158) at 0x34e148 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x276630 SV = PVAV(0x34efb8) at 0x276630 REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x0 FLAGS = (REAL) SIZE :-1 SV = RV(0x34e290) at 0x34e280 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x276630 SV = PVAV(0x34efb8) at 0x276630 REFCNT = 2 FLAGS = (PADMY,RMG) MAGIC = 0x27fde8 MG_VIRTUAL = &PL_vtbl_arylen_p MG_TYPE = PERL_MAGIC_arylen_p(@) MG_FLAGS = 0x02 REFCOUNTED MG_OBJ = 0x34e148 SV = PVMG(0x261f18) at 0x34e148 REFCNT = 1 FLAGS = (GMG,SMG,pIOK) IV = -1 NV = 0 PV = 0 MAGIC = 0x27fcf8 MG_VIRTUAL = &PL_vtbl_arylen MG_TYPE = PERL_MAGIC_arylen(#) MG_OBJ = 0x276630 ARRAY = 0x0 FILL = -1 MAX = -1 ARYLEN = 0x34e148 FLAGS = (REAL)

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        The reason a change was made:

        FromNicholas Clark
        reply-toEric Brine,
        perl5 porters <perl5-porters@perl.org>
        toEric Brine
        ccperl5 porters <perl5-porters@perl.org>
        dateFri, Sep 4, 2009 at 2:55 PM
        subjectRe: rvalue $#a adds magic

        On Fri, Sep 04, 2009 at 02:46:26PM -0400, Eric Brine wrote:
        > Before 5.10, $#a didn't add magic to @a

        > Since 5.10.0, it does.

        > Is that intentional?
        > What's the purpose?

        It's storing the value for $#a in the magic. Most arrays don't use $#a, which means that before 5.10 nearly every array consumes 1 pointers-worth of memory just to store NULL.

        I did it in 2005: http://perl5.git.perl.org/perl.git/commitdiff/a3874608cd3b

        Any operation that queries the size does the same thing:

        Not so.
        >perl -MDevel::Peek -le"my @a = qw(a b c); print @a-1; Dump \@a,1" 2 SV = RV(0x238c60) at 0x238c54 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x182a22c SV = PVAV(0x239a4c) at 0x182a22c REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x182521c FILL = 2 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL)

        If it's a bug, it's not attributable to Devel::Size.

        If it's a bug that reading $#a adds magic to @a, then that's not attributable to D::S.

        The bug in D::S is that it should be using the method that doesn't add magic.