msg_send调用会产生多少开销? [英] How much overhead does a msg_send call incur?
问题描述
我试图组合在一起,并运行由用户放在一起的任务列表。这些任务列表可以是数百或数千个项目长。
I'm attempting to piece together and run a list of tasks put together by a user. These task lists can be hundreds or thousand of items long.
从我所知道的,最简单和最明显的方法是构建一个数组,然后遍历它们:
From what I know, the easiest and most obvious way would be to build an array and then iterate through them:
NSArray *arrayOfTasks = .... init and fill with thousands of tasks
for (id *eachTask in arrayOfTasks)
{
if ( eachTask && [eachTask respondsToSelector:@selector(execute)] ) [eachTask execute];
}
对于桌面,这可能没有问题,但对于iphone或ipad ,这可能是一个问题。这是一个很好的方法去处理它,还是有更快的方式来完成同样的事情?
For a desktop, this may be no problem, but for an iphone or ipad, this may be a problem. Is this a good way to go about it, or is there a faster way to accomplish the same thing?
我问的是多少开销一个msg_send的原因发生的是我也可以做一个直接的C实现。例如,我可以组合一个链表,并使用一个块来处理下一个任务。
The reason why I'm asking about how much overhead a msg_send occurs is that I could also do a straight C implementation as well. For example, I could put together a linked list and use a block to handle the next task. Will I gain anything from that or is it really more trouble than its worth?
推荐答案
我假设你在谈论 objc_msgSend
,在这种情况下,Bill Bumgarner有一个优秀的
I assume you're talking about objc_msgSend
, in which case, Bill Bumgarner has an excellent
4 Part Series that is worth a read.
一般来说,我建议只使用Obj-C。这是所有的应用程序为iDevices使用,包括苹果,数百件物品不会杀死设备。
In general though, I would recommend simply using Obj-C. This is what all apps for the iDevices use, including Apple, and hundreds of items is not going to kill the device.
这篇关于msg_send调用会产生多少开销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!