in reply to Re^2: Shrunk array takes more memory than original
in thread Shrunk array takes more memory than original
why it gets larger from having half of its elements removed.
Because using $#array causes some magic to be attached to the array.
You don't even have to assign to $#array for this to happen, only reference it:
@b = 1 .. 10; print size \@b;; 256 print $#b; print size \@b;; 9 440
And yes, 184 bytes does seem excessive. You'd think that the magic could be stored once and simply referenced for each array using an 4/8-byte pointer.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Shrunk array takes more memory than original
by dave_the_m (Monsignor) on Nov 10, 2015 at 13:12 UTC | |
by BrowserUk (Patriarch) on Nov 10, 2015 at 13:16 UTC |