Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Re: what's faster than .=

by pg (Canon)
on Mar 08, 2003 at 17:36 UTC ( #241408=note: print w/replies, xml ) Need Help??

in reply to Re: what's faster than .=
in thread what's faster than .=

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://241408]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2018-10-18 16:08 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (102 votes). Check out past polls.