Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2016-12-03 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (56 votes). Check out past polls.