Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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?
[Discipulus]: choroba the Tk client print out an educated error message that it cant connect..
[Discipulus]: Can't connect to www.perlmonks.org: 80Invalid argument at ..perl5.26.64bit/ perl/vendor/lib/ LWP/Protocol/http. pm line 46, <__ANONIO__> line 34500.
[Corion]: Discipulus: That's weird, but maybe one of the machines is still wonky. I haven't looked :-/

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2017-10-24 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (288 votes). Check out past polls.

    Notices?