19.9. Memory
Intuitions about the relative space efficiency of different data structures aren't very reliable, either. If you are concerned about the memory footprint of a data structure that you are using, the Devel::Size module makes it easy to see how heavy the burden actually is: That might print something like: hash alone: 8,704,075 bytes data alone: 8,360,250 bytes ============================== total: 17,064,325 bytes which indicates that storing your 8.36MB of data in a hash has incurred an overhead of an additional 8.70MB for buckets, hash tables, keys, and other internals. The total_size( ) subroutine takes a reference to a variable and returns the total number of bytes of memory used by that variable. This includes both:
The size( ) subroutine also takes a variable reference, but returns only the number of bytes that the variable uses for itself, excluding the memory required to store its data. |