I do not mean to shrink the memory, I would like it to stay the same instead of growing.
I'm not adding anything new to the array and I don't get why it gets larger from having half of its elements removed.
| [reply] [Watch: Dir/Any] |
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.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [Watch: Dir/Any] [d/l] |
Because using $#array causes some magic to be attached to the array.
Technically speaking, a temporary magic object is created that points to the array. When the object is assigned to, it truncates the array. This object is freed (well, returned to the pool anyway) at the end of the statement. The array itself never gains any magic.
Dave.
| [reply] [Watch: Dir/Any] |