in reply to Why is the size even bigger after pack?
use feature qw( say ); use Devel::Size qw( total_size ); use Devel::Peek qw( Dump ); my $num = 1000; say total_size($num); Dump($num); say ''; my $packed = pack("w*",$num); say total_size($packed); Dump($packed);
5.12, 64 bit
24 SV = IV(0x768010) at 0x768018 <-- See SVt_IV image below REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 1000 <-- 8 bytes 48 SV = PV(0x752f28) at 0x768000 <-- See SVt_PV image below REFCNT = 1 Three more fields than SVt_IV FLAGS = (PADMY,POK,pPOK) PV = 0x7d6520 "\207h"\0 CUR = 2 <-- Even though only 3 are needed, LEN = 8 <-- 8 byte string buffer allocated
Are the greyed out fields outside of allocated memory or simply unused? [ See dave_the_m's reply ]
(The numbers still don't quite add up, but it should give you an idea.)
5.14, 32 bit
16 SV = IV(0x51a100) at 0x51a104 <-- See SVt_IV image below REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 1000 <-- 4 bytes 36 SV = PV(0x5e8cc4) at 0x51a054 <-- See SVt_PV image below REFCNT = 1 Four more fields than SVt_IV FLAGS = (PADMY,POK,pPOK) PV = 0x5b4334 "\207h"\0 CUR = 2 <-- Even though only 3 are needed, LEN = 12 <-- 12 byte string buffer allocated
(The numbers still don't quite add up, but it should give you an idea.)
Update: Adjusted based on dave_the_m's explanation.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why is the size even bigger after pack?
by dave_the_m (Monsignor) on Nov 03, 2011 at 09:14 UTC | |
by ikegami (Patriarch) on Nov 03, 2011 at 17:38 UTC | |
|
Re^2: Why is the size even bigger after pack?
by PerlOnTheWay (Monk) on Nov 03, 2011 at 08:37 UTC | |
by ikegami (Patriarch) on Nov 03, 2011 at 08:39 UTC | |
by PerlOnTheWay (Monk) on Nov 03, 2011 at 08:48 UTC | |
by ikegami (Patriarch) on Nov 03, 2011 at 17:51 UTC | |
by PerlOnTheWay (Monk) on Nov 04, 2011 at 01:30 UTC | |
| |
|
Re^2: Why is the size even bigger after pack?
by PerlOnTheWay (Monk) on Nov 03, 2011 at 08:50 UTC | |
by ikegami (Patriarch) on Nov 03, 2011 at 09:14 UTC |