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.
|
|---|