in reply to Re^2: how apply large memory with perl?
in thread how apply large memory with perl?

Ok, I'm stumped. Why in the world does the second line below result in so much less memory usage than the first? Just because it allocates the space before starting to fill it?

Yup. Its discussed in keys and perldata...

Used as an lvalue, "keys" allows you to increase the number of hash buckets allocated for the given hash. This can gain you a measure of efficiency if you know the hash is going to get big. (This is similar to pre-extending an array by assigning a larger number to $#array.) If you say keys %hash = 200; then %hash will have at least 200 buckets allocated for it--256 of them, in fact, since it rounds up to the next power of two. These buckets will be retained even if you do "%hash = ()", use "undef %hash" if you want to free the storage while %hash is still in scope. You can't shrink the number of buckets allocated for the hash using "keys" in this way (but you needn't worry about doing this by accident, as trying has no effect). "keys @array" in an lvalue context is a syntax error.
pre-extend, buckets, http://search.cpan.org/dist/illguts/index.html, http://search.cpan.org/perldoc/Devel::Size#UNDERSTANDING_MEMORY_ALLOCATION