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.
问题:
回答1:
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.
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.
Further, explicit ivar declaration has fallen out of routine usage with the introduction of declared properties.
回答2:
The layout of ivars is determined by the Objective-C compiler and there is no control provided in the language to effect this. While the article you've read might have been correct at some point in time for a particular compiler, it is reporting implementation-specific details you cannot rely on.
Trust the compiler to do a good job; or if layout is important to you use C or other language which provides control over layout.