问题描述
我在互联网上搜索优化Objective-C代码的提示,并遇到了此链接.在文章中,我看到了下面的注释,但我看不懂.
I was searching the internet for tips to optimizing Objective-C code and came across this link. In the article I saw the note below, which I am not able to understand.
推荐答案
本文已过时.曾经有一次,将Ivars存储在Objective-C实例中,就像存储结构的成员一样,因此内存对齐可能(略有影响)访问时间.
This article is out of date. It was at one time true that ivars were stored in an Objective-C instance just as the members of a struct are stored, and thus that memory alignment could (marginally) affect access time.
但是,现在可以间接访问至少在Apple的运行时中);实例现在保存了ivar的 offset ,并使用它来访问变量.由于所有这些偏移量都是相同的类型,并且您无法控制其他存储,因此可以避免此对齐问题.
Now, however, ivars are indirectly accessed (at least in Apple's runtime); the instance now holds the offset of the ivar, and uses that to access the variable. Since all those offsets are of the same type, and you have no control over the other storage, this alignment issue is obviated.
此外,通过引入已声明的属性,显式的ivar声明已脱离常规用法.
Further, explicit ivar declaration has fallen out of routine usage with the introduction of declared properties.
这篇关于实例变量声明的顺序在Objective-C中是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!