Re: copy and deepcopy
Re: copy and deepcopy
- Subject: Re: copy and deepcopy
- From: Andy Lee <email@hidden>
- Date: Tue, 23 Apr 2002 00:38:33 -0400
At 1:45 AM +0200 4/23/02, Ondra Cada wrote:
On Monday, April 22, 2002, at 11:50 , Robert Lee Dotson wrote:
[...]
If I send [myMatrix copy], will I get two objects with pointers
to the same data (values)? Or will I get two objects with distinct
yet identical copies of the data? Or will I just crash with a
sigbus?
Depends on how you have programmed the -copy method, which is
exactly what you want to do with a new class, if its instances
should be copiable.
More precisely, the -copyWithZone: method, which gets called by -copy.
There is no fixed rule for whether -copyWithZone: returns a shallow
or deep copy. It's up to you to decide and document your choice --
as Ondra said, it depends.
If in a given case you don't want -copyWithZone: to return a deep
copy, you can of course add your own -deepCopy method and call that
instead of -copy. Another implementation option is to use archiving
and archiving, which can be expensive, but can sometimes be closer to
what you want.
--Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.