in reply to array overhead
$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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: array overhead
by dave_the_m (Monsignor) on Jan 06, 2011 at 00:15 UTC | |
by ikegami (Patriarch) on Jan 06, 2011 at 17:41 UTC | |
by dave_the_m (Monsignor) on Jan 06, 2011 at 19:57 UTC |