Ah - yes, thank you. Of course, so [[NSArray alloc]init] is actually useless;
I hadn't thought of that. No one would ever declare an array that way.
One would have to init it with objects to be useful at all, and then it
presumably would point to different data than another NSArray (even nonmutable)
inited with objects.
On Sep 21, 2016, at 9:33 PM, Jens Alfke wrote:
> On Sep 21, 2016, at 9:19 PM, Jeff Evans <jev...@ars-nova.com> wrote:
> Is it really true what Jens says, that [[NSArray alloc]init] always
> returns the same pointer?
> If that is the case, how can one declare two separate arrays?
NSArray is immutable, so any two empty NSArrays are equal/identical.
Now, _mutable_ arrays are different — every call to [[NSMutableArray alloc]
init] returns a new instance.
The same thing is true of other immutable Foundation classes like NSDictionary,
NSString and NSNumber, so you’ll see the same optimization for e.g. short
strings and small integers. (In fact, the latter two are now implemented using
magic tagged pointers that don’t allocate memory at all!)
Cocoa-dev mailing list (Cocoaemail@example.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to arch...@mail-archive.com