Difference between Dispatch Queue and NSOperationQueue
Asked Answered
M

3

19

I am very new to GCD and threading. I have gone through the tutorials and getting very much confusion. Can some one explain in simple words.Please don't suggest apple developer links..

Thanks in advance !

Maximinamaximize answered 11/7, 2013 at 11:3 Comment(1)
Well in that case I can suggest SO links :) .. Here hope you find them useful ... #7079158 #10373831 #11677129 And two external links :- maniacdev.com/2010/03/… blog.spec-india.com/difference-between-nsthread-and-nsoperationHebephrenia
K
18

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.

It is 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.

check the below link,it may be helpful to you.

Operation Queue vs Dispatch Queue for iOS Application

Kingdon answered 11/7, 2013 at 11:25 Comment(1)
I have seen your answer regarding background process in THIS link.I need to run a recorder application for long time.Point me in the right wayMaximinamaximize
E
4

Operations provide us more control over the task like we can cancel a particular operation when ever we want or all operations at the same time. But this same thing can not be done using Dispatch Queues.

Further Dispatch Queues work on the concept of FIFO and where as the Operations does not.

For Operation we can prioritize the task and have control over them like which task to be executed first and which to be in the end by defining their priority.

Which is done by setting a property named "queuePriority" to be very low, low, normal, high, very high. many other such things can be done suing Operations and not by Dispatch Queues.

With Operations we can not do things serially as they are concurrent by default but this can also be achieved by adding dependencies of operations on each other like operation 2 is dependent over operation 1 and operation 3 is dependent on operation 2. Hence by doing this they will execute serially.

Et answered 10/1, 2019 at 14:5 Comment(0)
M
1

GCD is lower-level than NSOperationQueue, its major advantage is that its implementation is very light-weight and focused on lock-free algorithms and performance.

In general, you should use the highest level of abstraction that suits your needs. This means that you should usually use NSOperationQueue instead of GCD. NSOperationQueue gives you a lot more control over how your operations are executed.

Massotherapy answered 11/7, 2013 at 11:40 Comment(2)
Thanks for reply .. I heard that GCD is more convenient to use while the other having over head weight (Based on few tutorials..)Maximinamaximize
GCD can be more convent, the focus on lambdas/blocks definitely makes a lot of simpler uses easier to express. NSOperationQueue makes it easier to express individual operations that have dependencies more complex then "just not at the same time then anything else on queue X", or "FIFO and not at the same time as anything else on queue X". NSOperationQueue lets you say "A can't happen until B and C both finish" or "A can't happen until either A or B finish". However as "commonly overlooked" part of GCD queues can target other queues so you can express some non-trivial dependencies...Alderson

© 2022 - 2024 — McMap. All rights reserved.