Re: Concurrent loading of images ?
Re: Concurrent loading of images ?
- Subject: Re: Concurrent loading of images ?
- From: Jens Alfke via Cocoa-dev <email@hidden>
- Date: Fri, 8 May 2020 11:19:45 -0700
> On May 8, 2020, at 9:53 AM, Gabriel Zachmann via Cocoa-dev
> <email@hidden> wrote:
>
> So, I was thinking, maybe it helps to load the next image concurrently, while
> the current one is still being displayed.
Sure. Just be aware that if you're using NSImage, simply loading an NSImage
does not rasterize it; the class tries to be 'lazy' about doing work. So your
background task should explicitly render it, e.g. into an NSBitmapImageRep.
> I also read about the GCD's dispatch queues, but it seems to me that this
> would not be the suitable approach since I always only have one task running
> concurrently to the main thread.
Why not? Dispatch queues are always available. (The main thread is simply a
special queue.) You can run the background task by creating a single dispatch
queue and then using dispatch_async to call a block that does the work. The end
of the block would call dispatch_async back to the main queue and pass the
image as a parameter.
(Or you could use NSOperationQueue and NSOperation, although I've always found
those classes unnecessarily complicated for simple tasks.)
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden