objective-cmemory-alignmentivar

Does the order of instance variable declaration matter in 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.

enter image description here


Solution

  • 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.