• 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 release
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copy and release


  • Subject: Re: Copy and release
  • From: Nicko van Someren <email@hidden>
  • Date: Thu, 21 Oct 2004 23:21:50 +0100

On 21 Oct 2004, at 21:05, Evan Schoenberg wrote:

On Oct 21, 2004, at 10:35 AM, Nicko van Someren wrote:

It is quite common when writing programs for Cocoa that a data structure needs to be mutable while it is being filled but after that it would be useful for it become immutable in order to take advantage of the efficiencies that affords once the object has been set up.

This has been a wonder of mine for a long time in Cocoa.. do you have information on how precisely the immutable objects are more efficient? I've heard the claim before but never seen hard data either confirming or denying it.

If you make immutable copies of immutable NSString, NSDate, NSArray or NSDictionary objects (to pick a few important examples) you simply get the same object with the reference count incremented. This saves some data copying for simple objects and by the time you get to complex objects like dictionaries the cost of copying can get pretty high. You can test this with something like:

NSDictionary *d1 = [NSDictionary dictionaryWithObjectsAndKeys: @"Blah", @"Blah", nil];
NSDictionary *d2 = [d1 copy];
NSLog(@"The objects are %p and %p", d1, d2);

Nicko

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Copy and release
      • From: Paul Sargent <email@hidden>
References: 
 >Copy and release (From: Nicko van Someren <email@hidden>)
 >Re: Copy and release (From: Evan Schoenberg <email@hidden>)

  • Prev by Date: Re: Bug in NSArrayController? (immutable instead of mutable dictionaries)
  • Next by Date: Re: Bug in NSArrayController? (immutable instead of mutable dictionaries)
  • Previous by thread: Re: Copy and release
  • Next by thread: Re: Copy and release
  • Index(es):
    • Date
    • Thread