in reply to for-loop issue - swap gets crazy large

You are creating 100_000 arrays, each with references to arrays of 100_000 elements. That's 10_000_000_000 elements.

$ perl -MDevel::Size=total_size -E'$x = 1.2; say total_size($x);' 24

A scalar holding a floating point number takes 24 bytes, so we're up to 240 GB without counting the arrays themselves, the references and the overheard of the memory allocation system.

In a given loop pass, you never use any index of @distance other than $distance[$u], so you don't have to keep the other elements in memory. You could dump the results to disk (or whatever it is you do with them) instead of keeping them in memory.

[ Oops, too slow. I got interrupted mid-composition. ]

Replies are listed 'Best First'.
Re^2: for-loop issue - swap gets crazy large
by esolkc (Acolyte) on Aug 31, 2011 at 20:32 UTC
    ...but how can I "dump" them. do you have a -suggestion-?
      You could dump them as strings if you want something readable, or you could get the underlying bytes using pack 'F' to avoid precision loss.