in reply to Is there a way to find the size of a data structure?

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.

  • Comment on Re: Is there a way to find the size of a data structure?