in reply to why does this array take up so much memory?
If you look at it from the other direction, each value stored in the array only takes up about 32 bytes (even less, because the array itself has some overhead as well). I don't know much about perls internal memory structure, but every scalar has at least three slots, SV, PV and NV, for the string value, float value and integer value of said scalar. That's already 12 bytes taken up, plus another 4 bytes for the pointer from the array to that scalar (now at 16 bytes). The rest could be other overhead or simply more overhead from the scalars, which I didn't mention/know.
A matrix this huge might be better handled via C code as ints respective doubles, or a database, depending on how large your data will actually be.
If you really need a matrix this large, you should also consider what operations you want to perform on it, and whether a sequential storage in rows makes more sense - or whether floats hold enough precision to allow more complex operations such as multiplications/divisions without too much loss of precision...
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
|
|---|