Re: Copy and release
Re: Copy and release
- Subject: Re: Copy and release
- From: Paul Sargent <email@hidden>
- Date: Fri, 22 Oct 2004 13:24:51 +0100
Nicko van Someren wrote:
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.
A question I've had is when a container is said to be immutable, is it
still fair game to change the contents of the objects that are contained?
For example: An NSArray containing NSMutableString objects, or an NSData
object. Can you / Should you change the contents of the NSMutableStrings
in the NSArray or the Memory block pointed to by the NSData?
Should items contained in immultable container classes be considered
immutable?
Paul
P.S. Sorry for taking this further off-topic. As far as the OP goes, the
main effeciency point I've seen when dealing with mutable Vs. immutable
is that a copy of an immutable object can just be a reference to the
same object, but a mutable copy needs to be a full copy. Things is, why
do you need a copy? If it's to change it, then it needs to be mutable,
and you need a full copy. If it's just to call it by a different name,
then regardless of wether it's a mutable object or not you just need to
pass a reference around.
So, personally, while the addition of the method you're describing
wouldn't be a problem as far as I'm concernced, I wouldn't see myself
using it much if it did exist. Maybe I'm being niave though, and there
are other efficencies that I'm ignoring. Either way, it's not a bad
addition, just prossibly one of limited usefullness.
_______________________________________________
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