in reply to Re^4: perl5.10 Devel::Size behaviour changed? (bug report)
in thread perl5.10 Devel::Size behaviour changed?

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

  • Comment on Re^5: perl5.10 Devel::Size behaviour changed? (reason for magic)

Replies are listed 'Best First'.
Re^6: perl5.10 Devel::Size behaviour changed? (reason for magic)
by BrowserUk (Patriarch) on Sep 04, 2009 at 21:30 UTC

    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.
      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)