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 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屋!