I think you missed my point. I was throwing out the idea that maybe that model would translate to Perl. There are three ways I've seen memory allocation affected in general:
You'd run this with and without the big malloc/free and see if there's any difference. The big leap here is that these are not straight (flat) memory allocations in Perl -- you're also (I'd think) building up data structures (hashes, arrays). I did not dive into the code so I may be way off base here. But I did try this test just for kicks on Solaris 2.7. The big malloc/free came out a lot worse, so that theory can pretty much be buried ... at least on that platform. Here's a baseline difference. The runs take forever so I didn't get a good sample set. Kind of pointless I think.use strict; my $i = 120; my $n = 250000; my $x = {}; my @a; my $j; $#a = $n; # Up front, big malloc/free ... Does it make a difference? #keys %$x = ($i * $n); #$x = {}; while ($n-- > 0) { $x = {}; keys %$x = $i; for ($j = 0; $j < $i; $j++) { $x->{$j} = $j; } push(@a, $x); }
Times with the big malloc/free:
Times without it:Total Elapsed Time = 947.1299 Seconds User+System Time = 383.5699 Seconds
Total Elapsed Time = 497.0599 Seconds User+System Time = 376.4799 Seconds
In reply to Re: Re: How do I pre-allocate an array of hashes?
by steves
in thread How do I pre-allocate an array of hashes?
by jaa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |