Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Minimum Hash keys allocated?

by afoken (Chancellor)
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.


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

Replies are listed 'Best First'.
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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2023-12-08 16:51 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (36 votes). Check out past polls.