in reply to Sorting data that don't fit in memory
I'm no expert on internals, but I'm pretty sure you could save at least 1/2 of your memory by changing @amp_a from being an array of anonymous arrays (which has an RV, an AV and 2 SV's per element) to a straight array of scalars (only one SV per element).
Then, instead of carrying around your cumbersome, unpacked data, you can just unpack in the sort:
my @sortamp = sort{ unpack(..., substr(...$a)) <=> unpack(..., substr( +...$b) } @$amp_a;
It might be slow, but (hopefully) you won't run out of memory.
You don't mention what platform you're running on, but if it's little-endian, this ought to work (because the sort key is an integer at the end of your data):
my @sortamp = sort{ reverse($a) cmp reverse($b) } @$amp_a;
(A straight string compare with the most significant bit in front.)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Sorting data that don't fit in memory
by jeroenes (Priest) on Jan 24, 2001 at 16:04 UTC | |
by tye (Sage) on Jan 24, 2001 at 19:40 UTC | |
by jeroenes (Priest) on Jan 24, 2001 at 20:07 UTC |
In Section
Seekers of Perl Wisdom