There's Devel::Size. I remember complaints about it not being very accurate, but those were long ago and may have been caused by bugs that have long since been fixed. | [reply] |
Lately, I have been rereading "Extended and Embedding Perl" by Tim Jennes and Simon Cozens, and it contains beautiful drawings of the internal structures used by perl to represent data, it's easy to estimate memory consumption looking at them:
Scalars containing text, use around 4*9+len bytes on 32bit computers. Scalars with numbers sometimes use less memory.
Arrays use 4*(9+len) bytes plus the memory used by the contained items.
Hashes are a bit more complex, specially as keys can be shared, but roughly, they eat 4*(13+7*n_items) bytes plus all the key sizes (plus malloc overhead) plus the memory used by the elements. | [reply] |
You could use Storable, just freeze the structure in memory and print its length, i.e.
use Storable;
my %a = (
'a' => 'something..',
'b' => 'something else..',
)
print length(Storable::freeze(\%a))."\n";
This will give you a "rough ball-park sizeof" without the memory overhead of using a module like Devel::Size :-) | [reply] [d/l] |
Well, that would give the size of the Storable image of the data, not the live-in-RAM size... and I think the OP intended the latter.
So, for the OP: use Devel::Size, or study the sources...
| [reply] |