Are you sure about that?
Yes. I am very sure.
Unlike C, perl can do sparse arrays without using lots of memory for the empty slots,
No. It cannot.
The second assignment in your example (on a 64-bit system) results is the allocation of 134 megabytes of ram:
$a[0]=1; print total_size( \@a );; 232 $a[1]=1; print total_size( \@a );; 256 $a[2]=1; print total_size( \@a );; 280 $a[10_000_000]=1; print total_size( \@a );; 134217984
To gain a better appreciation for how Perl uses memory, see PerlGuts Illustrated and scan down to the AV heading.
In reply to Re^3: Array or Hash
by BrowserUk
in thread Array or Hash
by palanisamy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |