in reply to Re^2: Array or Hash
in thread Array or Hash
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Array or Hash
by chrestomanci (Priest) on Jan 21, 2011 at 16:14 UTC | |
by BrowserUk (Patriarch) on Jan 21, 2011 at 16:54 UTC | |
|
Re^4: Array or Hash
by ahmad (Hermit) on Jan 21, 2011 at 15:41 UTC | |
by BrowserUk (Patriarch) on Jan 21, 2011 at 15:43 UTC |