Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-20 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found