in reply to Re^2: What defines the choice of a Hash or an Array?
in thread What defines the choice of a Hash or an Array?
The hash allocates more memory in this case, and allocates more than the array in a lineal comparison for every filled key-value pair in the hash, and any contiguous index-value in the array.use Devel::Size qw(size); my @array; my %hash; my $array_size = size(\@array); my $hash_size = size(\%hash); print "Array: $array_size, Hash: $hash_size\n";
use Devel::Size qw(size); use Data::Dumper; my @array; my %hash; $hash{'f'} = 140; $array[141] = 142; print Dumper @array; my $array_size = size(\@array); my $hash_size = size(\%hash); print "Array: $array_size, Hash: $hash_size\n";
|
|---|