• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: copy and deepcopy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: copy and deepcopy (From: Ondra Cada <email@hidden>)

  • Prev by Date: Cocoa Drawing in NSOpenGLView?
  • Next by Date: NSOutlineView question
  • Previous by thread: Re: copy and deepcopy
  • Next by thread: DO and connecting to hostNames
  • Index(es):
    • Date
    • Thread