in reply to Re^4: Create dynamically different array names based on counter incrementation
in thread Create dynamically different array names based on counter incrementation
Actually, it requires very close to twice as much memory. Try it for yourself:
## Create a test datafile of ~ 4MB perl -E"say 'x 'x10 for 1 .. 2e5" > junk.dat ## Then load it into an array of arrays using a while loop ## and check the memory consumed using the Task Manager or TOP perl -E"$n=0;$a[$n++]=[split] while $_=<>; <STDIN>" junk.dat ## On my system the process has used 214.8 MB ## Now do the same thing using map perl -E"@a=map[split],<>; <STDIN>" junk.dat ## On my system this process has used 345.1 MB.
With map,
Whilst the final AoA will consume the same amount of memory in both cases, the memory consumed by the intermediate lists will have considerably increased thhe overall memory required to construct the final array.
And depending upon your OS, the time taken to build it can be considerable longer using map.
|
|---|