CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Memory usage increasing: Edit Log



robertico
Novice

Mar 29, 2013, 9:02 AM


Views: 375
Memory usage increasing

I'm running this script and memory usage is increasing while it's processing the file.

The file is approx. 10 Gb.

I've added 'undef' but it doesn't matter.

Every chunk is just 1 Mb, so why is memory usage increasing ? (memory usage is approximately equal to bytes read)



Code
#!/usr/bin/perl 

use Try::Tiny;
use strict;
use warnings;
use File::Basename;
use IO::Handle;

my $substr= 'messageid';
my $infile = 'D:\MyFile.bin';
my $file = basename( $infile );
open (INFILE, $infile) or die "Can't open $infile: $!";
binmode INFILE;

my $outfile = "+>>" ."D:\\" .$file .".txt";
open (OUTFILE, $outfile);
OUTFILE->autoflush(1);

my $data="";
my $n=0;
my $strStart=0;
my $strEnd=0;

while (($n = read INFILE, $data, 1048576, $offset) !=0) {
if ($data =~ /messageid/) {
$strStart = $-[0];
$strEnd = $+[0];
print OUTFILE $offset ."\t" .$strStart ."\t" .$strEnd ."\n";
$offset = $strEnd + 1;
undef $data;
}
else{
$offset = $offset + $n -9;
undef $data;
}
}

close (INFILE);
close (OUTFILE);



(This post was edited by robertico on Mar 29, 2013, 1:10 PM)


Edit Log:
Post edited by robertico (Novice) on Mar 29, 2013, 9:05 AM
Post edited by robertico (Novice) on Mar 29, 2013, 9:05 AM
Post edited by robertico (Novice) on Mar 29, 2013, 1:10 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives