Hi David,

Your instructions helped me definitely. I made up a script testing free memory before 
loading a file. There seems to be a tight relationship between the file size and the 
amount of memory used by MacPerl. This should be sufficient to prevent "out of memory" 
conditions.

I also tried filling memory with arrays. It was much less successful. I was not able 
to predict well used storage. When MacPerl blows out, MacOS crashes, the MacPerl heap 
is bad, and one or more volumes need repair. Rather undesirable.

Here is the script and output. 'Taken' and 'free' figures vary slightly with each run. 
Thanks for help.

#!/usr/local/bin/perl -w
# test memory used

use Mac::Memory;
$\="\n";
my @sac; my $fr; my $n=5;
my $fil='xxxxx'; # whatever file for testing
print 'file info size: ',-s $fil;
open IN, "<$fil" or die ".. $fil not opened";
print 'initial free: ',$fr=&FreeMem();
for (0..$n) {seek IN,0,0;
        local $/; $sac[$_] = <IN>;
        print 'taken: ',$fr-&FreeMem(),', free: ',$fr=&FreeMem();
};
for (0..$n) {print "file $_: ",length $sac[$_]};
__END__
file info size: 209282
taken: 209376, free: 1933136
taken: 209392, free: 1723744
taken: 209376, free: 1514368
taken: 209392, free: 1304976
taken: 209424, free: 1095552
taken: 209408, free: 886144
file 0: 209282
file 1: 209282
file 2: 209282
file 3: 209282
file 4: 209282
file 5: 209282
- -

On Mon, 20 Jan 2003 11:40:11 -0600 Greenblatt & Seay wrote:

Try this...
  1) Start up MacPerl
  2) Start up Memory Mapper and select "Update Regularly" from the "File" menu.
  3) Note the amount of memory assigned to Macperl (use "Get Info").
This number should be close to what Memory Mapper has for MacPerl in the  "Size" 
column.
  4) Note what Memory Mapper has for MacPerl in the "Free" column.
  5) Run the script below and compare  MacPerl's "Free" column in Memory Mapper with 
the output from the script. Keep watching because the script runs for 25  seconds.

You'll probably have to reposition the MacPerl window so you can see it and Memory 
Mapper at the same time.

David Seay
http://www.mastercall.com/g-s/

#!perl

use Mac::Memory;

         print "FREE MEMORY...\n";
         &print_FreeMem;
         for $x (1..5) {
                 sleep 5;
                 &print_FreeMem;
         }

         print "\n\nFINISHED";

sub print_FreeMem {
         $freeMem  = FreeMem();
         $freeMemK = int($freeMem/1024);
         $result = sprintf("%6d", $freeMemK);
         print "$result K\n";
}

__END__

Reply via email to