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


In reply to Array of Hash interface to an Array of Array? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.