in reply to Re^5: perl5.10 Devel::Size behaviour changed? (reason for magic)
in thread perl5.10 Devel::Size behaviour changed?

Hm. Pre-5.10, every array that didn't use $#array, wasted 1 pointer.

Post 5.10, every array uses that pointer to point to a 12 or 24-byte block of memory whether it is ever used or not.

And the very act of attempting to check to see if there is any magic attached, causes there to be magic attached.

That makes no sense at all to me.

Now the only way D::S can avoid causing the magic to be attached is to either not bother looking to see if there is any; or to dereference the magic pointer directly...

A microscopic optimisation attempt that causes a macroscopic [sic] pessimisation. Autovivifying magic just because someone wants to know if there is any is...


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.
RIP PCW It is as I've been saying!(Audio until 20090817)
  • Comment on Re^6: perl5.10 Devel::Size behaviour changed? (reason for magic)

Replies are listed 'Best First'.
Re^7: perl5.10 Devel::Size behaviour changed? (reason for magic)
by ikegami (Patriarch) on Oct 28, 2009 at 18:03 UTC
    Commits 02d85cc37a4acecafdc2f0b45640b03cd1f4ac71 and 28c5b5bcd7f52e6b2219508a1066cd0ccc8dd19a fix this when $#array is used as a rvalue. You'll see these changes in 5.11.2 (next month's dev release) and 5.12 (early to mid 2010)

        Oops, I forgot what this thread was really about when I posted. $#array is fixed. AvARYLEN isn't changed. AvARYLEN doesn't exist as a field, so don't try to measure its size. The following code shouldn't be executed in 5.10+:

        if (AvARYLEN(thing)) { if (check_new(tv, AvARYLEN(thing))) { total_size += thing_size(AvARYLEN(thing), tv); } }

        Test with bleadperl and with those lines present:

        perl -MDevel::Peek -MDevel::Size=total_size -wle' my @a = qw( a b c ); Dump(\@a,1); # Shows no magic print total_size \@a; # 224 Dump(\@a,1); # Shows magic $#a=$#a; # Add magic Dump(\@a,1); # Shows magic print total_size \@a; # 224 '

        Test with bleadperl and with those lines commented out:

        perl -MDevel::Peek -MDevel::Size=total_size -wle' my @a = qw( a b c ); Dump(\@a,1); # Shows no magic print total_size \@a; # 168 Dump(\@a,1); # Shows no magic $#a=$#a; # Add magic Dump(\@a,1); # Shows magic print total_size \@a; # 224 '

        Update: Fixed reply to reflect the actual usage of AvARYLEN by the module. It's not used to determine the length of arrays as I had originally indicated.

        Update: Added tests.