![]() |
|
P is for Practical | |
PerlMonks |
Shrunk array takes more memory than originalby kroach (Pilgrim) |
on Nov 10, 2015 at 12:03 UTC ( #1147349=perlquestion: print w/replies, xml ) | Need Help?? |
kroach has asked for the wisdom of the Perl Monks concerning the following question: I'm using the $# feature to shrink an array. After shrinking to half the size, the array seems to take a bit more memory. How is that possible? (perl 5.10 on 64-bit GNU/Linux) Output:
Is there a way to shrink the array without causing it to grow (and probably be reallocated)? UPDATE: It seems splice doesn't cause the same effect.
Output:
Furthermore, after running a few simple benchmarks, it turns out the splice method is about as fast as last index assignment, so it seems splice doesn't do unnecessary copying in void context.
Back to
Seekers of Perl Wisdom
|
|