NSNotificationCenter 与委托 - 哪个更快?

2023-07-28移动开发问题
0

本文介绍了NSNotificationCenter 与委托 - 哪个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经阅读了很多关于每种方法的优缺点的信息,并且我知道代表通常是针对一个听众的,而通知是针对许多听众的.问题是关于性能的.

I have read a lot about the pros and cons of each , and i know delegates are usually for one listener, and notifications are for many. The question is about performance.

我已阅读:NSNotificationCenter 与委派(使用协议)?

我正在通过通知从麦克风向另一个班级发送音频信号.我知道我应该在这里使用委托,但我的问题是:委托会更快吗?因为我可以看到我有一些帧速率问题(降低),我想知道原因是否可能是使用通知而不是委托,或者没有关系?

I am sending audio signals from mic, to another class by notification . i know that here i should use the delegate BUT my question is : does delegates will be faster ? because i can see i have some frame rate issue(decreased), and i would like to know if the cause could be the using of notification instead of delegate, or there is no relation ?

推荐答案

委托的开销更少,因此执行速度更快.

Delegates come with less overhead and will therefore be executed much faster.

但是,一般来说,您应该只在可能成为问题的地方查看性能主题.对于像发送通知和调用委托这样的一次性任务,这永远不会成为问题.但是,当您计划在循环中使用变量(取决于数据)执行这些操作时,或者对于您已获取或接收数据的许多数据对象,无法预测会有多少 - 这些情况是我会考虑性能优化.

However, in general you should look on performance topics only there where they are likely to be an issue at all. For once-off tasks like sending a notification vs calling a delegate this should never be an issue. But when you plan to perform these in a loop with a variable (depending on data) number of intarations or for a number of data objects where you have fetched or received the data an cannot predict how many there will be - those are the situations where I would consider performance optimization.

这篇关于NSNotificationCenter 与委托 - 哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

游戏中心 facebook 喜欢
Game center facebook like(游戏中心 facebook 喜欢)...
2024-08-12 移动开发问题
3

Objective-C++ 导入 C++ 类失败,未找到 cassert
Objective-C++ importing C++ class fails, cassert not found(Objective-C++ 导入 C++ 类失败,未找到 cassert)...
2024-08-12 移动开发问题
10