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

Re: Is there a way(maybe tool?) to know the amount of memory an array takes?

by Anonymous Monk
on Oct 22, 2011 at 02:41 UTC ( #933012=note: print w/ replies, xml ) Need Help??


in reply to Is there a way(maybe tool?) to know the amount of memory an array takes?

I've seen this done

my $before = current_memory(); my $after = current_memory(); SomethingSomething(); print join "\n", ' Before ', format_memory($before), ' After ', format_memory($after), ' Diff ', format_memory($after - $before), '' ; sub format_memory { my ($self, $memory) = @_; 1 while $memory =~ s/^([-+]?\d+)(\d{3})/$1,$2/; return "$memory KB"; } sub current_memory { my $self = shift; my $out = `ps -o rss= -p $$`; $out =~ s/^\s*|\s*$//gs; $out; }


Comment on Re: Is there a way(maybe tool?) to know the amount of memory an array takes?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2014-08-20 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls