How to detect memory usage in hash?

Discussion in 'Perl Misc' started by sonet, Oct 26, 2005.

  1. sonet

    sonet Guest

    How to know how many memory usage in a hash??
    I just can use top to see the memory usage?

    -----How to rough estimate ?---

    my %hash;
    for (my $i=0;$i<=10000;$i++){
    $hash{abc}{$i}='testing';
    }
     
    sonet, Oct 26, 2005
    #1
    1. Advertising

  2. sonet wrote:

    > How to know how many memory usage in a hash??
    > I just can use top to see the memory usage?
    >
    > -----How to rough estimate ?---
    >
    > my %hash;
    > for (my $i=0;$i<=10000;$i++){
    > $hash{abc}{$i}='testing';
    > }


    For a non-portable linux solution, read /proc/$$/status, and look for a line
    with 'VmSize'.

    gtoomey
     
    Gregory Toomey, Oct 26, 2005
    #2
    1. Advertising

  3. sonet

    Guest

    "sonet" <> wrote:
    > How to know how many memory usage in a hash??


    That depends on many things.

    > I just can use top to see the memory usage?


    Sure, if your system has top. Of course, it will be memory of the
    entire perl program, not just the hash. To do it from withing Perl,
    I usually use "my $mem = (`ps -p $$ -o rss `)[1];", which gives just the
    resident size of the whole program, but is usually good enough.
    There is also Devel::Size, but I often find it to be unreliable and that
    it causes worse problems than the ones I'm trying to use it to solve.

    Xho

    >
    > -----How to rough estimate ?---
    >
    > my %hash;
    > for (my $i=0;$i<=10000;$i++){
    > $hash{abc}{$i}='testing';
    > }


    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Oct 26, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. metfan
    Replies:
    2
    Views:
    4,863
    Robert Olofsson
    Oct 21, 2003
  2. hvt
    Replies:
    0
    Views:
    1,220
  3. hvt
    Replies:
    0
    Views:
    1,497
  4. rp
    Replies:
    1
    Views:
    555
    red floyd
    Nov 10, 2011
  5. Replies:
    3
    Views:
    277
Loading...

Share This Page