$a=[@$a] can be used to shrink the array. (Well, create a new one the minimal size.)
$ perl -MDevel::Peek -e'push @$a, $_ for qw( a b c d e ); Dump($a,1); +$a=[@$a]; Dump($a,1);' SV = IV(0x817bc44) at 0x817bc48 REFCNT = 1 FLAGS = (ROK) RV = 0x816c158 SV = PVAV(0x816d1c8) at 0x816c158 REFCNT = 1 FLAGS = () ARRAY = 0x8177928 FILL = 4 <----- 5 visible elements MAX = 11 <----- 12 elements allocated ARYLEN = 0x0 FLAGS = (REAL) SV = IV(0x817bc44) at 0x817bc48 REFCNT = 1 FLAGS = (ROK) RV = 0x816cea8 SV = PVAV(0x816d1dc) at 0x816cea8 REFCNT = 1 FLAGS = () ARRAY = 0x8183cb8 FILL = 4 <----- 5 visible elements MAX = 4 <----- 5 elements allocated ARYLEN = 0x0 FLAGS = (REAL)
But you might only end up fragmenting your memory, leaving less usable free memory behind.
In reply to Re: array overhead
by ikegami
in thread array overhead
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |