> Le 10 août 2017 à 16:09, Charles Srstka <cocoa...@charlessoft.com> a écrit :
> 
>> On Aug 10, 2017, at 8:59 AM, Alastair Houghton 
>> <alast...@alastairs-place.net> wrote:
>> 
>> On 10 Aug 2017, at 14:57, gerti-cocoa...@bitart.com 
>> <mailto:gerti-cocoa...@bitart.com> wrote:
>>> 
>>> On Aug 10, 2017, at 02:18, Alastair Houghton <alast...@alastairs-place.net> 
>>> wrote:
>>>> 
>>>> Personally I *would* still discourage +new in favour of class-specific 
>>>> convenience constructors because I think it’s less expressive and also 
>>>> less consistent (e.g. +array is better, in my opinion, than +new, not 
>>>> least because +arrayWithObjects: and others exist).
>>> 
>>> [NSArray new] := [[NSArray alloc]init]
>>> 
>>> [NSArray array] := [[[NSArray alloc]init]autorelease]
>>> 
>>> +array and friends came along with the introduction of autorelease pools, 
>>> to replace +new with something that didn't imply ownership (the oft 
>>> mentioned special meaning of "new" as prefix). So while with ARC they are 
>>> essentially equivalent, previously they were not.
>> 
>> Yes, I know that, thanks.
>> 
>> The point is, with ARC, they’re equivalent, and most new code uses ARC, so, 
>> again, I’d discourage +new in favour of class-specific convenience 
>> constructors.
>> 
>> Kind regards,
>> 
>> Alastair.
> 
> They’re equivalent syntactically, but performance-wise, +array and friends 
> will cause the object to be put into an autorelease pool. Therefore, +new is 
> better for performance.

Putting an object into an autorelease pool is very cheap. It is just a write of 
the pointer value in a thread local array. When using ARC, the object is still 
pushed in the autoreleased stack, but it may be immediately pop by the caller. 
So yes, +array still have a couple of additional operations to perform,  but it 
should be mesure to tell if this is significant performance wise.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to