Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Minimum Hash keys allocated?

by afoken (Parson)
on Sep 26, 2010 at 18:20 UTC ( #862104=note: print w/ replies, xml ) Need Help??


in reply to Minimum Hash keys allocated?

Premature optimization is the root of all evil. Just don't do that. Perl will handle allocation good enough most of the times. There may be rare cases where preallocation may be useful, but then, you would use Devel::NYTProf or similar first to find and eliminate other bottlenecks.

To save keystrokes, use my %hash=(); or just my %hash;, both are technically equal. Some people (including me) prefer the first form, refusing to rely on the implementation details of Perl to initialize the variable with an empty hash / empty array / undefined scalar, other people think that the documentation is very clear on this fact and the initializing assignment is just too much and redundant work.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)


Comment on Re: Minimum Hash keys allocated?
Select or Download Code
Re^2: Minimum Hash keys allocated?
by halfcountplus (Hermit) on Sep 26, 2010 at 18:50 UTC

    In fact, pre-allocating can save some headaches if you know the data structure is going to be a very large one, qv:

    mem usage

    Pay close attention to what ikegami says in this part:

    Re^4: mem usage

    As this sort of hack made a very real difference -- it is not simply a matter of setting the number of slots.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-12-25 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls