That data structure is going to take up about 11.7 Gigabytes of memory. And that's with the degenerate case you give where each HoHoH has a single digit integer as its data. (Reduce the outer loop to 10 so it will fit into memory, put in a busy/wait loop so you have time to look up the memory usage before it exits, then look in the process manager to get the memory usage.)
use strict;
use warnings;
my %hash = ();
foreach my $a (1..10) {
foreach my $b (1..4000) {
foreach my $c (1..10) {
foreach my $d (1..7) {
$hash{$a}{$b}{$c}{$d} = $d;
}
}
}
print "$a\n";
}
print "here\n";
next while (!<STDIN>);
I come up with about 247000KB used. Take out about 2K for the perl interpreter overhead, multiply by 50, divide by 10242... 11.7 GB.
Even converting to arrays, it takes up about 5 Gigabytes.
It would seem that either you are going to have to rework your algorithm or use a database. I'm not clear what exactly you are attempting to accomplish. |