如何在obj-C的C函数中向自身发送消息?

如何在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];
}