in reply to returning large arrays from functions
E.g., does perl avoid copying of data in the following cases?
No. The array is copied in both those cases.
There are two ways of avoiding that:
sub large_array_ref { my $large_array_ref = []; ...populate @$large_array_ref... return $large_array_ref; } my $c = large_array_ref(); $c->[ ... ];
sub large_array_ref { my $large_array_ref = shift; ...populate @$large_array_ref... return; } large_array_ref( \my @c ); $c[ ... ];
With a suitably chosen name for the sub, the latter looks less awkward:
populateThingArray( \my @c ); $c[ ... ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: returning large arrays from functions
by LanX (Saint) on Nov 19, 2010 at 16:45 UTC |