Silly Computer Engineer.
Lin~Jing~Sen
Something as small as the flutter of the butterfly's wing
can ultimately cause a typoon half way around the world

Group Blog
 
All Blogs
 
Memory Leak (0) : How can I make my Perl program take less memory?

//perldoc.perl.org/perlfaq3.html#How-can-I-make-my-Perl-program-take-less-memory

แบบว่า trace file การ simulate มันก็ใหญ่อะนะ เลยหาวิธีทำยังไงให้ใช้ memory น้อยลง

วิธีการหนึ่งที่ดีมากๆคือ การอ่านไฟล์ทีละบรรทัด แทนที่จะโหลดทั้งไฟล์ขึ้น memory ที่หนังสือส่วนใหญ่มันสอน

ของเก่า แบบโหลดทั้งไฟล์

open(FILE,"file.txt");
@data = ;
foreach (@data) {
# ...
}

ของใหม่ที่ดีกว่า
open(FILE,"file.txt");
while () {
print "$_\n"; #แต่ละบรรทัดเก็บในตัวแปรระบบชื่อ $_
}

โอ้ว การมช้แรม ลดฮวบๆ สุดยอด ไม่น่าโง่มานาน อายจัง... =.="


Create Date : 20 มีนาคม 2549
Last Update : 8 เมษายน 2549 0:13:11 น. 0 comments
Counter : 400 Pageviews.

ชื่อ :
Comment :
  *ใช้ code html ตกแต่งข้อความได้เฉพาะสมาชิก
 

nmapxp
Location :
กรุงเทพ Thailand

[Profile ทั้งหมด]

ฝากข้อความหลังไมค์
Rss Feed

ผู้ติดตามบล็อก : 1 คน [?]





Friends' blogs
[Add nmapxp's blog to your web]
Links
 

 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.