Perrin Harkins wrote:
>
> > $foo->{$i} = [ @record ];
>
> You're creating 14000 arrays, and references to them (refs take up space
> too!). That's where the memory is going.
>
> See if you can use a more efficient data structure. For example, it
> takes less space to make 4 arrays with 14000 entries in each than to
> make 14000 arrays with 4 entries each.
>
So I turned it around:
$col holds now 18 arrays with 14000 entries each and prints the correct
results:
#!/usr/bin/perl -w
$col = {};
$line = "AAAA\tBBBB\tCCCC\tDDDD"; # 4 string fields (4 chars)
$line .= "\t10.99"x9; # 9 float fields (5 chars)
$line .= "\t" . 'A'x17; # 5 string fields (rest)
$line .= "\t" . 'B'x17; #
$line .= "\t" . 'C'x17; #
$line .= "\t" . 'D'x17; #
$line .= "\t" . 'E'x17; #
@record = split "\t", $line;
foreach $j ( 0 .. $#record )
{
$col->{$j} = [];
}
for ( $i = 0; $i < 14000; $i++ )
{
map { $_++ } @record;
foreach $j ( 0 .. $#record )
{
push @ { $col->{$j} }, $record [$j];
}
print "$i\t$col->{0}->[$i],$col->{5}->[$i]\n" unless $i % 1000;
}
<>;
1;
and gives:
SIZE RSS SHARE
12364 12M 1044
Wow, 2 MB saved ;-))
I think, a reference is a pointer of 8 Bytes, so:
14.000 * 8 = approx. 112 KBytes - right?
This doesn't explain the difference of 7 MB calculated and 14 MB
measured.
Ernest
--
*********************************************************************
* VIRTUALITAS Inc. * *
* * *
* European Consultant Office * http://www.virtualitas.net *
* Internationales Handelszentrum * contact:Ernest Lergon *
* Friedrichstra�e 95 * mailto:[EMAIL PROTECTED] *
* 10117 Berlin / Germany * ums:+49180528132130266 *
*********************************************************************
PGP-Key http://www.virtualitas.net/Ernest_Lergon.asc