Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Monks,
My question is related to memory requirements for a large number of hashes.
I DP reasonably large arrays of identically structured records. For naming convenience, I use a hash for each record with the field names as the hash keys
For example:
my $people = [ { name => 'fred', age => 25, height => 1.5 }, { name => 'sally', age => 20, height => 1.4 }, ]; for my $person (@$people} { print $person->{name},"\n"; }
The record structures are much larger, with typically 80-100 fields and about 4K of data. When dealing with datasets where the data is say 60MB, I am seeing memory usage of 600MB - I believe that this is related to the hash algorith and how many buckets are used etc.
I have searched CPAN, but not found anything - I was wondering if there are any magic Tie modules out there that let me pretend that I am working with an Array of Hash, but that are implemented under the hood as an Array of Array - where the fieldname gets efficiently mapped to an index?
Something like:
my $people = [ [ 'fred', 25, 1.5 ], [ 'sally', 20, 1.4 ], ]; my $accessor = accessor->new( keys => ['name','age','height'], data => $people, ); for my $person (@$people} { print $person->{name},"\n"; }
Thanks in advance,
Jeff
|
|---|