Re: Copy and release
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