Your analogy doesn't help.
You are constructing a 3-dimensional array, and you are running out of memory. Assuming $data[ 0..X ][ 0..Y ][ 0..Z ];
What we need from you is:
- the maximum size of those three dimensions X, Y, Z?
- Are the dimensions contiguous or sparse?
If sparse, the approximate density?
If one or more of X,Y & Z can run say 3000 .. 4000; or if instead of using every number between 0 ..m; you only use every 10th or 100th; then you can save substantial space by using a hash instead of an array for that dimension of the structure.
- Do you need to build the entire dataset before you can calculate your statistics>
Could you build (say) all of $data[Y][Z] for X=1; calculate the stats; and then discard that before building all $data[Y][Z] for X=2?
- What are you storing in each element of that 3d array?
Is it just a number? If so, how big will that number get?
If, for example, each element of the array held an integer < 255, the you can easily substitute a string for the 3 level arrays and save huge amounts of memory.
Eg. This constructs a 100x100x100 3d array of small integers which requires 33MB of memory.
@data = map[ map[ map int( rand 256), 0..99 ],0..99 ], 0..99;;
print total_size \@data;;
This on the other hand construct 100x100x100 2D array of strings. It contains the exact same information, but it only requires 1.6MB:
@data = map[ map pack( 'C*', map int( rand 256), 0..99 ), 0..99 ], 0..
print total_size \@data;;
If you give us the information we ask for, we can almost certainly help you reduce your memory requirements.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||