Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Why is the size even bigger after pack?

by PerlOnTheWay (Monk)
on Nov 03, 2011 at 05:23 UTC ( [id://935590]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^3: Why is the size even bigger after pack?
by chromatic (Archbishop) on Nov 03, 2011 at 06:08 UTC

    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.

Re^3: Why is the size even bigger after pack?
by Tux (Canon) on Nov 03, 2011 at 07:38 UTC

    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://935590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found