Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
572
678
I'm currently using a dispatch queue to concurrently process and save images taken by the camera in my app.

I need to be able to limit the number of concurrent operations or the app can run out of memory. I know I can set max number of concurrent operations for a NSOperationQueue but I have not been able to find any info regarding dispatch blocks...

Code:
// the queue I need to limit
imageProcessingQueue = dispatch_queue_create("com.app.imageProcessingQueue", DISPATCH_QUEUE_CONCURRENT);


- (void) saveImage:(UIImage *)image {
	
	dispatch_async(imageProcessingQueue, ^{
		
		// Process the image and save to disk.
		
		dispatch_async(dispatch_get_main_queue(), ^{
			
			// Save the image path and other image info to core data.
		});
	});
}
 

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
572
678
Thanks for that but in this particular instance there's another answer.
If you need a NSOperationQueue, use a NSOperationQueue.

By using NSOperationQueue's addOperationWithBlock I was able to use the existing code pretty much and it works great :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.