作者sweetwords (米虫三號)
看板Perl
標題[問題] memory out?
時間Wed Sep 24 20:25:56 2008
最近跑一支從 20w 多筆的資料庫中,要抓出來其中一個欄位
可是不知道為啥會跑出 memory out 的情況
我下 top 看 memory 資源現在是這樣
Mem: 119M Active, 1588M Inact, 209M Wired, 70M Cache, 112M Buf, 8280K Free
Swap: 4096M Total, 245M Used, 3851M Free, 5% Inuse
程式主要是像下面這樣,只是一個很簡單的從資料庫叫出欄位而已 ._.
有 google 一下,主要是說 perl 對於 array 會吃掉太多記憶體
可是不知道我以下這樣寫,哪裡有吃掉很多記憶體呢 QQ?
my $query = "select * from fed_etd_main";
my $sth = $dbh->prepare($query);
$sth->execute;
$sth->bind_col(1,\$identifier,undef);
my $j=1;
while(($sth->fetch))
{
print $j.":".$identifier."\n";
$j++;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.117.74.176
推 LiloHuang:用Devel::Size去看看到底是哪邊吃一堆記憶體 09/28 09:12
推 LiloHuang:我懷疑這樣query列出的資料太多 可能要用WHERE限制條件 09/28 09:13
推 LiloHuang:或者用LIMIT 限制筆數看看 09/28 09:13