较旧版本的iOS和OS X上的ARC [英] ARC on older versions of iOS and OS X

查看:77
本文介绍了较旧版本的iOS和OS X上的ARC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是为了清除我对ARC的概念性理解中的一些疑问.如果ARC是一种编译时技术,为什么它不能在所有版本的iOS和OS X上使用?

This is to clear up some doubt in my conceptual understanding of ARC . If ARC is a compile time technology why isnt it available on all versions of iOS and OS X ?

推荐答案

ARC不仅仅是一种编译时技术.它还依赖于某些运行时组件.这有两个部分:

ARC isn't just a compile-time technology. It also relies on some runtime components. There's two parts to this:

  1. 参考计数.在编译时,ARC引入了对许多辅助函数的调用.这些都是在线文档,但重要的是objc_retain()objc_release()objc_autorelease().这些功能与在对象上调用-retain-release-autorelease相同,但是在ARC下,可以使用运行时函数进行一些额外的优化(特别是当方法返回自动释放的对象,并且调用者会将值存储到一个强变量中,则可以完全跳过自动释放+保留).这些运行时功能增加了操作系统要求.幸运的是,如果您以较旧的操作系统为目标,则Xcode可以链接到名为libarclite的静态库中,该库提供了这些功能的实现,从而使您可以在以较旧的操作系统(例如iOS 4.3)为目标时使用ARC.缺点是这些功能没有真正的" ARC所具有的优化,因此性能可能会稍有下降.

  1. The reference counting. At compile-time, ARC introduces calls to a bunch of helper functions. These are all documented online, but the important ones are objc_retain(), objc_release(), and objc_autorelease(). These do the same things as calling -retain, -release, or -autorelease on the object, but there's some extra optimizations that can be done under ARC with the runtime functions (notably, when a method returns an autoreleased object and the caller stores the value into a strong variable, the autorelease + retain may be able to be skipped entirely). These runtime functions are what adds the OS requirement. Luckily, if you target an older OS, Xcode can link in a static library called libarclite that provides implementations of these functions, thus allowing you to use ARC when targeting an older OS (e.g. iOS 4.3). The downside is these functions don't have the optimizations that "true" ARC does, so performance may suffer slightly.

零基准支持弱化.这还需要一组运行时函数,并对运行时内存管理的内部原理进行一些更改,并在框架中进行一些更改以更好地支持将弱引用归零.内存管理方面的变化特别是为什么无法像其他ARC一样使用libarclite向后移植归零弱参考支持的原因.

Zeroing weak reference support. This also requires a set of runtime functions, plus some changes to the internals of how memory management works in the runtime, plus some changes in the frameworks to better support zeroing weak references. The memory management changes specifically are why zeroing weak reference support cannot be backported using libarclite like the rest of ARC can.

这篇关于较旧版本的iOS和OS X上的ARC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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