in reply to Re^2: Trouble getting size of list returned from sub
in thread Trouble getting size of list returned from sub
sub get_size { my @a = big_list(); return scalar @a } my $size = get_size();
However, in a simple test, that uses the same memory as a global array that does the same thing.
Perl, generally speaking, does not release memory back to the OS unless your system is running out of memory. The memory from lexical variables can be claimed and reused by Perl, but it doesn't go back to the OS.
All of the other methods created an array in addition to what was copied on the stack. map only creates an array of 1s in addition to what was copied on the stack; thus it uses less memory (unless your original data is no bigger than integers, of course) (and yes, this was not always true in older versions of Perl).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Trouble getting size of list returned from sub
by Anonymous Monk on Nov 26, 2012 at 15:24 UTC | |
by ColonelPanic (Friar) on Nov 26, 2012 at 15:40 UTC |