in reply to Re: Memory Error Printing Multiple Hashes Simultaneously
in thread Memory Error Printing Multiple Hashes Simultaneously

Glad you got an speedy explanation. It seems so obvious once it is pointed out, but then no one else here spotted the cause either:(

It very non-intuative that the rates of memory growth you were seeing could be attributed to the simple act of stringifying previously numeric values. Once you know what to look for, it is easy to see the how quickly the memory usage grows when ths happens.

A (minimum) of 70% growth for integers:

c:\Perl\test>p1 [0] Perl> use Devel::Size qw[ total_size ];; [0] Perl> @a = (0) x 1e6;; [0] Perl> print total_size( \@a );; 20000056 [0] Perl> $_.='' for @a;; [0] Perl> print total_size( \@a );; 34000056

And a whopping 300% for floats.

c:\Perl\test>p1 [0] Perl> use Devel::Size qw[ total_size ];; [0] Perl> @a = ( 1.0 ) x 1e6;; [0] Perl> print total_size( \@a );; 24000056 [0] Perl> $_.='' for @a;; [0] Perl> print total_size( \@a );; 75000056

Definitely one to remember if you are running close to the memory limits of your machine.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: Memory Error Printing Multiple Hashes Simultaneously
by bernanke01 (Beadle) on Feb 01, 2006 at 18:14 UTC
    Yup, and the actual use-case was floats (simplified down to integers for debugging). Thanks for all your help with this BrowserUk.