Hi,
I am getting some "out of memory" error while trying to run a perl script I wrote. I googled for this but failed to fix, and thought if you could shed some light.
Basically, I am using the CPAN module GraphViz to create a graph from my input data (say, from a file named full.txt). Now, I am reading just one line at a time, so the error is not due to large input filesize. I tracked the error and found that it gets in trouble when, at the end, it is trying to save the graph (data structure) as a .png (or .gif) file. So, commenting out this line does not crash the program:
$g->as_png("1.png"); # save the graph as a png image
I tested on a small input file and it successfully produced the desired .png file.
The errors are:
dot(3100) malloc: *** vm_allocate(size=1069056) failed (error code=3)
dot(3100) malloc: *** error: can't allocate region
dot(3100) malloc: *** set a breakpoint in szone_error to debug
out of memory
Any clue on how I can increase the memory or get around this in any other way?
Here is my perl script:
#!/usr/bin/perl -w
use GraphViz;
use strict;
use warnings;
my $inputfile = $ARGV[0];
open(INPUTFILE, $inputfile) || die "Could not open $inputfile\n";
my $start_run = time(); # get timestamp at the beginning of creatin
+g the graph
my $countLine = 0; # count matched I-lines of text
my $g = GraphViz->new(); # create a new graph
while (my $line = <INPUTFILE>) {
chomp($line);
if( $line =~ m/\bI\b/i ) { # Does $line has an uppercase 'I' anyw
+here in it?
#print "$line\n";
$countLine++;
# Split the I-line into 5 fields
my ($timestamp, $field2, $temple, $macaque1, $macaque2) = split '
+', $line;
print "$timestamp : $temple : $macaque1 : $macaque2\n\n";
# Add an edge to the graph for this I-line
$g->add_edge( $macaque1 => $macaque2, label => "$timestamp\n$temp
+le");
}
}
$g->as_png("1.png"); # save the graph as a png image
my $end_run = time(); # get timestamp at the end of creating the graph
my $run_time = $end_run - $start_run;
print "Job took $run_time seconds. Processed $countLine I-lines of tex
+t.\n";
close(INPUTFILE);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.