No such thing as a small change | |
PerlMonks |
Re: Re: what's faster than .=by pg (Canon) |
on Mar 08, 2003 at 17:36 UTC ( [id://241408]=note: print w/replies, xml ) | Need Help?? |
Your post and testing results, made me thinking why the approach Perl uses to allocate memory for hash is totally different from what it does for string. My answer is that they had different expectations for string and hash. For string, most of the time, you don't expect it to grow that much. More importantly, even it grows, it does not indicate it will continue to grow. But hash is different, as a collection of elements, you expect it to grow all the time. More importantly, if you see some growth, it would be reasonable for you to expect more growth. To speed up, Perl simply assume that what happened would happen again, so let's double the memory allocated, when what has been allocated is all used up. It is all about expectation and analysis of behavior.
In Section
Seekers of Perl Wisdom
|
|