you can't even load the @lines array of a 400MB file in 1GB of RAM
I believe there is this thing called "virtual memory"... Note that in my original reply I also noted:
And I'd check how much paging space is configured. It sounds like that could be increased.
Virtual memory can be very useful. Especially if you sort something that can fit in physical memory and so only run through paging the larger things around a few times rather than having sort have to page through things something like O(log(N)) times.
Hence my creation of a quite small array that is easy to sort. Actually, this makes me think of a minor change that might have a non-trivial impact on the size of the array that I sort:
my @size= map 0 + ( split /\t/, $_ )[2], @in;
# ^^^ store numbers not strings
my @idx= sort { $size[$a] <=> $size[$b] }, 0..$#in;
@in= @in[@idx];
You could also play games to reduce the number of times you run through @in (each time causing paging), but I think the gains from that would be relatively minor in comparison while the complexity required is relatively great. Except, perhaps, for the last iteration:
for( @idx ) {
print $in[$_], $/;
}
(Though, I half expect Perl to do @in= @in[@idx]; in-place.)
|