YYAsyncLayer icon indicating copy to clipboard operation
YYAsyncLayer copied to clipboard

NSOperationQueue 和 NSOperation 方式

Open Beyond-Chao opened this issue 6 years ago • 2 comments

YY 大神你好,请教一个问题:

你用多个串行队列来实现并发、控制线程数量,避免GCD在并行队列上执行耗时任务时开辟过多线程、消耗系统资源。如果通过NSOperationQueue 和 NSOperation的方式,控制maxConcurrentOperationCount 为YYAsyncLayerGetDisplayQueue中的queueCount,能够实现同样的效果嘛?

Beyond-Chao avatar Mar 30 '18 04:03 Beyond-Chao

I prefer NSOperationQueue ~

Tangdixi avatar Sep 26 '18 17:09 Tangdixi

NSOperation的实现其实也是CGD了,所以一般情况下NS一层怎么都会有性能损失的,NSOperation感觉比较适合用在你要管理线程状态的时候,比如NSOperation的start,ready等的状态,可以看SW和YYImageWeb,大量用到NSOperation,主要原因是如果你要对并行并行队列做状态控制的话,比较麻烦,所以不得不用NSOperation,但假如你只想控制线程数量,何必直接用CGD串行队列呢?

xll503721 avatar Jan 21 '19 05:01 xll503721