in reply to Perl Optimization
Now imagine that the example above is actually a reference to an enormous object, with grand-children, great-grand-children, and great-great-great-great-grandchildren. From what I can see, every time you de-reference some or all of the object, a copy is made.my $href = { 'x' => { 'y' => { 'z' => [ $xref, $yref, $zref ], }, 'strange' => { ..... }, }, 'charm' => { .... }, };
In the case where these are really big objects, as some of ours are, that would be rather rough, especially if we iterate through children, then grand-children, then deeper still.foreach my $obj (%{$href}) # This dereference ^ causes a deep copy to be made
In line 7, a deep copy of the list is made. If we change the sub to take not a reference, but the whole list, is this equivalent, or is it different?01: my $list = [1, 2, 3]; 02: doStuff($list); 03: 04: sub doStuff 05: { 06: my $listRef = shift; 07: foreach $listElement (@{$listRef}) 08: { 09: print "$listElement \n"; 10: } 11: }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: Perl Optimization
by tilly (Archbishop) on Jun 01, 2001 at 18:37 UTC | |
|
Re: Re: Perl Optimization
by Cybercosis (Monk) on Jun 01, 2001 at 20:29 UTC | |
by tye (Sage) on Jun 01, 2001 at 21:29 UTC |