操作队列与iOS应用程序的调度队列 [英] Operation Queue vs Dispatch Queue for iOS Application

查看:223
本文介绍了操作队列与iOS应用程序的调度队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 操作队列和调度队列之间的区别是什么?

  2. 在什么情况下更适合使用每个?


推荐答案

NSOperationQueue 早于大中央调度,不使用GCD执行操作(这在Mac OS X上是不同的)。

NSOperationQueue predates Grand Central Dispatch and on iOS it doesn't use GCD to execute operations (this is different on Mac OS X). It uses regular background threads which have a little more overhead than GCD dispatch queues.

另一方面, NSOperationQueue 给你更多的控制如何执行操作。例如,您可以定义单个操作之间的依赖关系,这对于纯GCD队列是不可能的。也可以取消在 NSOperationQueue 中排队的操作(只要操作支持它)。

On the other hand, NSOperationQueue gives you a lot more control over how your operations are executed. You can define dependencies between individual operations for example, which isn't possible with plain GCD queues. It is also possible to cancel operations that have been enqueued in an NSOperationQueue (as far as the operations support it). When you enqueue a block in a GCD dispatch queue, it will definitely be executed at some point.

要总结一下, NSOperationQueue 可以更适合于可能需要被取消或具有复杂依赖性的长时间运行的操作。

To sum it up, NSOperationQueue can be more suitable for long-running operations that may need to be cancelled or have complex dependencies. GCD dispatch queues are better for short tasks that should have minimum performance and memory overhead.

EDIT :似乎有关<$ c $的文档c> NSOperationQueue 已过时,并且 在iOS 4.0及更高版本上使用GCD。

EDIT: It seems the documentation about NSOperationQueue is outdated and it does use GCD on iOS 4.0 and later.

这篇关于操作队列与iOS应用程序的调度队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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