实例变量声明的顺序在Objective-C中是否重要? [英] Does the order of instance variable declaration matter in Objective-C?

查看:73
本文介绍了实例变量声明的顺序在Objective-C中是否重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上搜索优化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中是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆