如何在obj-C的C函数中向自身发送消息? [英] How to send a message to self in a C function in obj-C?

查看:69
本文介绍了如何在obj-C的C函数中向自身发送消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C函数(音频队列服务"中的回调函数),我想向自己发送消息.怎么做? 如果我输入[self message],则会出现错误:

I have a C function(a callback function in Audio Queue Services) and I want to send message to self. How to do that? If I type in [self message], there is an error:

Use of undeclared identifier 'self'

推荐答案

您不在实时回调(例如音频)中执行objc消息.原因是objc消息传递不是恒定的时间,并可能锁定,导致错过最后期限,导致音频丢失.静态或动态(virtual)C ++调用和C函数调用当然是固定时间的,并且适合于实时上下文.

You don't perform objc messages in realtime callbacks, such as audio. The reason for this is that objc messaging is not constant time, and may lock, resulting in missed deadlines, resulting in audio dropouts. Static or dynamic (virtual) C++ calls and C function calls are of course constant time, and suitable for realtime contexts.

如果它不是实时/音频回调,那么一种选择是传递self作为用户信息或上下文参数:

If it were not an realtime/audio callback, then one option would be to pass self as the user info or context parameter:

void SomeCallback(t_stuff* const stuff, void* userInfo) {
  MONClass * Self = (MONClass*)userInfo;
  [Self doSomething];
}

这篇关于如何在obj-C的C函数中向自身发送消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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