Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Why is the size even bigger after pack?

by grantm (Parson)
on Nov 03, 2011 at 04:37 UTC ( #935581=note: print w/ replies, xml ) Need Help??


in reply to Why is the size even bigger after pack?

Devel::Size it telling you how many bytes are taken up by the C structure(s) that are used to represent your Perl variable. The numbers you're getting suggest it takes 24 bytes to represent a scalar containing an integer and 48 bytes to represent a scalar containing a string. I can't say I find that particularly surprising.


Comment on Re: Why is the size even bigger after pack?
Re^2: Why is the size even bigger after pack?
by PerlOnTheWay (Scribe) on Nov 03, 2011 at 05:23 UTC

    What's the point of pack if it takes more memory after packing?

      What did you think it would do?

      pack turns a list of values into a string according to a specific format. If you want to interact with something else which expects values in a specific format (a system call, a foreign function, a binary protocol), pack is your tool. If you want to use less memory, you need something else.


      Improve your skills with Modern Perl: the free book.

      Your example only shows one single case. An SV can hold IV's as well as PV's at the same time and a PV representation of 1 takes less space than that of big numbers. YMMV (even with different versions of perl):

      $ cat test.pl use v5.12; use Devel::Size "total_size"; for my $num (1, 1000, 100_000_000) { say "Value $num:"; say total_size ($num); say total_size (pack "w*", $num); } for my $num ("1", "1000", "100_000_000") { say "Value $num:"; say total_size ($num); say total_size (pack "w*", $num); } $ perl test.pl Value 1: 64 48 Value 1000: 64 48 Value 100000000: 72 48 Value 1: 48 48 Value 1000: 48 48 Value 100_000_000: 56 48 $

      Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935581]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2015-07-06 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (71 votes), past polls