As I understand it, shallow and deep copies refer to how far "down the
pointers" you go. Somebody more knowledgeable, please correct me if I goof it
up. :-)
Say you have a pointer p1 associated with another pointer p2, which itself is
associated with a target t1. Now suppose you say p1 = p2. A shallow copy
would stop at one level, by copying the _pointer_ p2 to p1. A deep copy would
dereference p2, and copy the target t1 to p1.
Thus, shallow and deep refer to how far down the association chain you go.
When you're doing a linked list, you want shallow copies, for instance;
otherwise, the compiler would traverse the whole list to get to a target.
I'm not sure if that was the best example... somebody who knows more comp sci
could probably give you a terser explanation.
Alvaro Fernandez
Dick Hendrickson wrote:
>
> I've seen something like this before and never understood it. Could
> someone give a brief explanation of "deep" and "shallow" copies. And
> maybe explain why one could or couldn't be used in some common cases.
>
> Thanks
>
> Dick Hendrickson
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|