Working on one project I stay before problem of memory requirements. Tried to use tied hashes I doscover taht my code eat more and more of my memory. Each iteration through all data in that hash cost me other memory space. After some experiments I've got following code which demonstrate this behaviour. It looks like problem with Storable.
What goes on? Where is my memory?
#!/usr/bin/perl -w
use strict;
use Set::Scalar;
use Storable qw(nfreeze thaw);
my $iterations = 20;
my $set_count = 100;
my $data = 'abcdefgh';
srand();
for (my $cycle = 0; $cycle < $iterations; $cycle ++) {
{
my $tmp = $data;
my $r_arr;
$tmp .= chr(int(rand(26))+65);
for (my $set = 0; $set < $set_count; $set ++) {
my $scalar_set = Set::Scalar->new(split(//, $tmp));
push @$r_arr, thaw( nfreeze( $scalar_set ) );
}
}
&procinfo;
}
exit 0;
sub procinfo {
my @stat;
open( STAT , '<', "/proc/$$/stat" ) or die "Unable to open stat file
+";
@stat = split /\s+/ , <STAT>;
close( STAT );
printf "Vsize: %3.2f MB\t", $stat[22]/1048576;
print "RSS : $stat[23] pages\n";
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|