开发者

Cocoa nonatomic properties

开发者 https://www.devze.com 2023-01-02 05:24 出处:网络
When you look at some Objective-C code开发者_如何学Go, you often see class properties defined as non-atomic. Why? Does it give you some performance boost when you\'re not working with threads, or is t

When you look at some Objective-C code开发者_如何学Go, you often see class properties defined as non-atomic. Why? Does it give you some performance boost when you're not working with threads, or is there some other reason?


nonatomic accessors are faster because they don't have to lock. That's about all there is to it. From the documentation:

If you do not specify nonatomic, then in a reference counted environment a synthesized get accessor for an object property uses a lock and retains and autoreleases the returned value—the implementation will be similar to the following:

[_internal lock]; // lock using an object-level lock
id result = [[value retain] autorelease];
[_internal unlock];
return result;

If you specify nonatomic, then a synthesized accessor for an object property simply returns the value directly.

0

精彩评论

暂无评论...
验证码 换一张
取 消