Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Devel::Size reports different size after hash access

by BrowserUk (Patriarch)
on Oct 25, 2016 at 20:25 UTC ( [id://1174732]=note: print w/replies, xml ) Need Help??


in reply to Devel::Size reports different size after hash access

The problem is that you are using the numeric values of the hash in a string context: print $fh "$key $hash{$key}\n";; thus perl converts what were IVs (internal integers) into PVs (internal strings), caching the result in the expectation you might use them in a string context again.

As an IV, each value requires 24 bytes, but once converted to a string and stored in a PV, each value requires ~56 bytes.

You can avoid the conversion being cached by making perl convert a temporary value to a string for printing like this:

printf $fh "$key %d\n", 0+$hash{$key};

That will avoid the memory growth.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found