jinyedge's note
{http://www.jinyedge.pe.kr}


Hi, this is jinyedge. I'm a software developer. I hope you can find some useful information in my homepage.


jinyedge at gmail.com
Since 2001.12.05

 

 
Subj Cont
 
Subj: Perl, Checking memory usage with cdb file.
Mtime: 2010-01-27 01:27:35

#!/usr/bin/perl
use CDB_File;
use Proc::ProcessTable;

#---------------------------------------------------------------------
sub memory_usage{
    my $t = new Proc::ProcessTable;
    foreach my $got(@{$t->table} ){
        next if not $got->pid eq $$;
        return $got->size;
    }
}

#---------------------------------------------------------------------
# Main.

# Create cdb file.
$t = new CDB_File("t.cdb", "t.$$");
for(1..10000000){
    $t->insert($_, "value = $_");
}

$t->finish;

# Load cdb file.
$c = tie %h, `CDB_File`, `t.cdb` or die "tie failed: $!\n";
print $h{100}, "\n";

# Check memory usage.
print `memory: `. memory_usage() / 1024 / 1024 ."\n";

undef $c;
untie %h;