Please advise me to how to achieve NSOperation and NSOperationQueue functionality in C++.
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.
Grand Central Dispatch is a low-level C API that interacts directly with Unix level of the system. NSOperation is an Objective-C API and that brings some overhead with it. Instances of NSOperation need to be allocated before they can be used and deallocated when they are no longer needed.
NSOperationQueue works best when tasks are discrete, synchronous and live in the same thread (eg they are more or less atomic), the queue can be used as basic thread pool though in almost any situation.
An operation queue invokes its queued NSOperation objects based on their priority and readiness. After you add an operation to a queue, it remains in the queue until the operation finishes its task. You can't directly remove an operation from a queue after you add it. Note.
NSOperation
is a class for managing non-critical tasks. You create Operations, and place them on the NSOperationQueue
and each operation is performed as the app executes.
There is no such "equivalent" in C++. C++ is a language, as NSOperationQueue
is part of FoundationKit a part of OSX and iOS, a set of Objective-C objects, that aren't part of the objective-c standard.
What you'll need to research is the Android paradigms for doing task concurrency, and use those. Or you can just manually download the assets from the server, in-lieu of any managed task library.
A rough substitute for NSOperation: std::packaged_task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With