Re: NSImage from bitmap - then delete bitmap
Re: NSImage from bitmap - then delete bitmap
- Subject: Re: NSImage from bitmap - then delete bitmap
- From: Trygve Inda <email@hidden>
- Date: Fri, 22 Jul 2016 07:45:53 -0700
- Thread-topic: NSImage from bitmap - then delete bitmap
>> Currently it blocks at this point, but I need to avoid that.
>
> It’s not really clear why this needs to be avoided. The time to draw the
> pixels should be a few milliseconds, a small fraction of the time your thread
> needs to run, even at its fastest.
Because the main thread sometimes needs to ask the worker threads to
terminate. If it does this after performOnMainThread has been called by a
worker thread, but before the main thread has processed it, then the main
thread will block waiting for the worker thread to exit, but the worker
thread has already blocked when it called performOnMainThread.
Very rare, but it can happen.
>> Since it can't
>> block,
>> the pixels need to be copied to the main thread because as soon as
>> they get handed to the main thread, the worker thread will erase the
>> original pixel buffer to start drawing a new image into it.
>
> Copying the image is likely to be just as slow/fast as drawing it, so the copy
> isn’t going to help speed up your thread. Both operations have to iterate over
> the pixels; drawing *IS* copying.
Speed isn't really the issue. The issue is changing the code so that the
worker thread never has to block. To do so the pixels need to handed off to
the main thread in such a way that the worker thread can then destroy the
original pixels (by writing over them with new data)
>> The copy needs to exist long enough to be drawn into a window by the main
>> thread and can then be released.
>
> Understood, but you may as well keep it around until the next version of the
> image is passed across - the previous one will be released at the same time
> when setting the property.
Yup - that's possible too.
_______________________________________________
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