Now, the classic tradeoff for speed is memory. You have to remember more with hashes, cause every value has a key associated with it. Arrays, on the other hand, just store that value.
From what you've described, speed is much more important to you than memory, especially since you reset your cache every so often. (This doesn't free the memory to the OS, but it does free it back to the Perl interpreter.)
Now, there's an even better thing with hashes with regards to memory. Perl pre-allocates a certain amount of space whenever you use any variable, be it a scalar, array, or hash. (This, as you might guess, is for speed considerations.) With arrays, the number I've most often heard is that around 50 scalars-worth are pre-allocated. Hashes pre-allocate 16 scalars-worth (or less) - 2 scalars per bucket. Now, hashes grow pretty quickly (for example, 65 scalars would need space for 100 in a list, but 128 in a hash), but if you're not going beyond 32, you're still in the same ballpark for space.
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
In reply to Re: Internals question - "exists" for hash keys versus grep'ing array
by dragonchild
in thread Internals question - "exists" for hash keys versus grep'ing array
by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |