iOS:调用Objective-C方法的处理开销是多少? [英] iOS: What is the processing overhead in invoking an Objective-C method?

查看:141
本文介绍了iOS:调用Objective-C方法的处理开销是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一些实时音频处理代码,它将在音频单元的渲染回调中执行。

I am writing some real-time audio processing code, which is to be executed in an audio unit's render callback.

此线程处于最高优先级系统识别。

This thread is at the highest priority level the system recognises.

Apple指示最小化此调用中正在进行的处理量。他们的一个建议是避免使用Objective-C方法。

Apple instructs to minimise the amount of processing that goes on in this call. One of their recommendations is to avoid Objective-C method invocation.

但为什么?

Objective-C方法被调用?什么是实际开销?

What happens when an Objective-C method is invoked? what is the actual overhead?

推荐答案

Objective-C方法解析是动态的。在其他语言(如C或C ++)中,函数调用在编译时设置,实质上是跳转到包含该函数的地址。然而,在Objective-C中,方法调用被实现为发送消息,这些消息不能以相同的方式工作。有一个查找过程而不是硬编码跳转。

Objective-C method resolution is dynamic. In other languages such as C or C++, a function call is set at compile time, essentially as a jump to the address that contains the function. In Objective-C however, method calls are implemented as 'sending messages' which don't work in the same way. There is a lookup process involved instead of a hardcoded jump.

此查找过程是与定位要运行的方法的地址相关联的开销。它非常优化,但对于某些类型的代码,开销会导致性能问题。

This lookup process as an overhead associated with locating the address of the method to run. It is very optimised, but for certain types of code the overhead can cause performance issues.

Mike Ash给出了精彩的文章关于Objective-C消息传递的内容,如果您对其他细节感兴趣的话。

Mike Ash gives a great writeup on what happens with Objective-C messaging if you're interested in additional detail.

这篇关于iOS:调用Objective-C方法的处理开销是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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