Objective-C中的标记指针 [英] Tagged pointers in Objective-C
问题描述
回答此问题时,我注意到现代的Objective-C运行时使用标记的指针. 文章由Mike Ash和其注释.请注意,它们用于某些NSNumber
和NSDate
实例.
While answering this question I noted that modern Objective-C runtime uses tagged pointers. The article by Mike Ash and its comments note that they are used for some NSNumber
and NSDate
instances.
这让我考虑了不同平台的完整方案表:
Which got me thinking about the complete table of scenarios for different platforms:
OSX/iOS 32/64位Objective-C运行时在何处使用标记的指针?
推荐答案
OS X和iOS都使用64位代码中的带标记的指针对象.当前都没有使用32位代码中的任何带标记的指针对象,尽管原则上并非没有可能.优化类和优化值的特定集合经常更改.开源objc4/runtime/objc-internal.h描述了在至少一个OS版本中使用的以下类集:
OS X and iOS both use tagged pointer objects in 64-bit code. Neither currently uses any tagged pointer objects in 32-bit code, though in principle it's not impossible. The specific set of optimized classes and optimized values changes frequently. Open-source objc4/runtime/objc-internal.h describes this set of classes that was used in at least one OS version:
OBJC_TAG_NSAtom = 0,
OBJC_TAG_1 = 1,
OBJC_TAG_NSString = 2,
OBJC_TAG_NSNumber = 3,
OBJC_TAG_NSIndexPath = 4,
OBJC_TAG_NSManagedObjectID = 5,
OBJC_TAG_NSDate = 6,
OBJC_TAG_7 = 7
这篇关于Objective-C中的标记指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!