in reply to Re^3: Why is the size even bigger after pack?
in thread Why is the size even bigger after pack?

I read it somewhere, but I can't recall it now.

I'll also implement it this way if I was Larry:)

  • Comment on Re^4: Why is the size even bigger after pack?

Replies are listed 'Best First'.
Re^5: Why is the size even bigger after pack?
by ikegami (Patriarch) on Nov 03, 2011 at 17:51 UTC

    I find it odd that Larry you would waste memory like that.

    See dave_the_m's post. He explains how even the ungreyed box is in previously allocated memory.

      You mentioned it's in previously allocated memory

      why??Isn't it created on the fly?

      Perl allocates more memory than required for string, that's what xpv_cur/xpv_len is there for

        No, the SV body isn't created at all for SVt_IV scalars.

        A SV usually has a head block and a body block (that's in addition to any string buffer, etc). SVt_IV scalars, rather exceptionally, don't have a body. Or rather they have a body, but it's location overlaps the head so that it never needs to be allocated.

        5.12, 64 bit ints, 64 bit floats - - -+ <---+ : | : +04 | Usual SV head SVt_IV : | --> +-----------------+ --> +-----------------+ +08 | | Pointer to body ------+ | Pointer to body ------+ +04 | | | +04 | | +0C | | | | | +08 +-----------------+ | +08 +-----------------+ +10 | REFCNT | | | REFCNT | +0C +-----------+-----+ | +0C +-----------+-----+ +14 | FLAGS | SVt | | | FLAGS | SVt | +10 +-----------+-----+ | +10 +-----------+-----+ +18 | PV ---> +---------- | | IV/UV | +14 | | ... | +14 | | +1C | +---------- | | | +18 +-----------------+ | +18 +-----------------+ +20 | Usual SV body | +-----------------+ <---+ | NV | | | +04 | | +-----------------+ +08 | CUR | | | +0C | | +-----------------+ +10 | LEN | | | +14 | | +-----------------+ +18 | IV/UV | | | +1C | | +-----------------+ +20