I stand corrected. At some point, I probably read the linked list thing that LanX mentioned and now misremembered it.
To convince myself, I threw together:
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use Memory::Usage;
my @array1;
my @array2;
my $mu = Memory::Usage->new();
$mu->record('ready to go');
$array1[5268] = 1;
$mu->record('array1 has an element');
$array2[8675309] = 1;
$mu->record('array2 has an element');
$mu->dump();
Running this on a Debian 8.11 machine with perl 5.20.2, I get the result:
time vsz ( diff) rss ( diff) shared ( diff) code ( diff)
+ data ( diff)
0 20824 ( 20824) 2568 ( 2568) 1916 ( 1916) 8 ( 8)
+ 920 ( 920) ready to go
0 20824 ( 0) 2568 ( 0) 1916 ( 0) 8 ( 0)
+ 920 ( 0) array1 has an element
0 88600 ( 67776) 70416 ( 67848) 2048 ( 132) 8 ( 0)
+ 68696 ( 67776) array2 has an element
The array index 5268 that I used for array1 is a magic number, apparently corresponding to the minimum size that my
perl allocates for an array when it's initially declared. If I increase the index to 5269, it shows an additional 132k (all the numbers are in kilobytes) allocated when array1 is assigned to.