John W. Kennedy wrote:
>Yes, it does round up. However, A) it only rounds up the number of
>buckets; it doesn't "preallocate memory" for the whole hash; and B) the
>rounding up will happen as you add items to the hash, anyway, so using
>keys() won't use any more memory, unless (obviously!) you set it to too
>large a number, whereas using keys() /will/ make your program a little
>faster, because it won't have to, every time a power-of-2 line is
>crossed, create a new hash, twice as big, copy the old hash into it, and
>then delete the old hash.

It doesn't preallocate? Appears I've fallen into a hole in my knowledge. So what's the difference between preallocation and "rounding up the number of buckets"?

If there's no preallocation, could you clarify the statement that without keys() my program would have to create a new hash, etc.? Isn't creating a new hash a form of (er, just-in-time) preallocation?

Doesn't the statement that "using keys() won't use any more memory unless...you set it to too large a number" contradict the statement that keys() doesn't preallocate? Or am I being inadvertently obtuse?

Idle curiosity prompts me to pose this conundrum: what happens if I set keys() *at* a power of two? That is, if I do

        keys(%hash) = 256;

will I get 256 buckets? Or 512?

Thanks to all who answered the initial query!

Deane
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to