in reply to why does this array take up so much memory?

Variables in perl take up at least pointer and two native ints (for just an undef) plus at least the size of the data being stored for ints and double-precision floats. So in this case you've got a pointer, two ints, and a double, which will snag 20 bytes per array element, not counting the array overhead itself. So you've 16M elements, times 20, plus array overhead.

Perl, as has been pointed out, is not stingy with memory. There are ways around it, but none used yet. (Perl 6 has provisions to be much stingier, but it's not done yet)

This seems to be a common thing. I may well throw together a Stingy::Array module or something to get better packing.

  • Comment on Re: why does this array take up so much memory?

Replies are listed 'Best First'.
Re: Re: why does this array take up so much memory?
by rdfield (Priest) on Jan 27, 2003 at 10:51 UTC
    I may well throw together a Stingy::Array module or something to get better packing
    I, for one, would be very grateful for such a module.

    rdfield

      I went looking after I posted, and there is Tie::IntegerArray, but it's only a 0.1 version and works through Bit::Vector, so I'm not sure how fast it is. I'm going to poke at it in a day or so, and if it's not reasonably snappy I will put a module together myself. (Might anyway, as something to do a Parrot benchmark against, but that's a separate issue... :)