in reply to Re: My scalars swell
in thread My scalars swell

@plaque is a list of 86 hashes, each of which has 3 keys (3 scalars) associated to three scalars (two being refs), both refs referring to a hash of about 507 keys (507 scalars), each associated to a scalar which is a reference to a list of 6 scalars. Therefore,

86 * (3 + 507 + 507*6) = 305472 scalars. Memory usage after forced numification 12444 kilobytes, yielding about 40 bytes per scalar (ignoring the overhead of lists and hashes themselves which I cannot measure due to lack of knowledge), which sounds pretty much the same as much simpler tests yield. But the question remains...

40 bytes per scalar?! I hardly need 4 bytes per scalar...

Ah well, guess I'll have to either forget it or go play with vec and substr. Which is not nice nor clean solution. I wonder if perl6 is going to do something about this.

Replies are listed 'Best First'.
Re (tilly) 3: My scalars swell
by tilly (Archbishop) on Oct 22, 2001 at 00:34 UTC
    While the space usage by Perl may astound you, when you start accounting for it, it turns out to be much more reasonable than you might think. For instance a basic scalar value has to have a pointer to a data structure, keep a reference count, and keep a bunch of flags to know what it currently is. That is 12 bytes of overhead for general behaviour related metadata, and we don't even have the data yet! Plus the things you are discounting, arrays and hashes and things, are all non-trivial data structures which involve lots of associated metadata, and then wasted space for internal buffering.

    For more on this, you should take a look at Perl 5 Internals by Simon Cozens. And after that, dive into perlguts.

    Perl isn't C. But the nice features don't come for free.