Re: drawing in a separate thread
Re: drawing in a separate thread
- Subject: Re: drawing in a separate thread
- From: "Kyle Sluder" <email@hidden>
- Date: Fri, 2 May 2008 04:13:27 -0400
On Fri, May 2, 2008 at 3:13 AM, Graham Cox <email@hidden> wrote:
> I realise these questions must sound rather fundamental, but nothing in the
> Cocoa Drawing Guide or Thread Guide really addresses them. I have used
> threads before to perform tasks not involving drawing, so I'm not completely
> unfamiliar with them, but I haven't tried drawing on a secondary thread
> before.
The reason these questions aren't addressed in the guide is because
they are highly dependent on just what you are doing. Only you can
determine when something needs to be updated.
As for spawning multiple threads, you want your drawing to be
performed really quickly. I would strongly advocate keeping a thread
around for the life of your view and having it sit an a loop that ends
with it performing a blocking read on some IPC port. That way it gets
scheduled off the processor but you don't suffer the thread-creation
or -destruction penalty every time you perform a draw.
Drawing from a secondary thread isn't an easy task, so perhaps you
might want to consider whether it's possible to avoid doing so. Maybe
you can draw into an image on the secondary thread, and then when
necessary use -performSelectorOnMainThread:withObject:waitUntilDone:
to send the view a -setNeedsDisplay: message when after your thread
has completed its drawing. Then the view can overwrite its own buffer
with it. Be careful of synchronization issues, of course.
HTH,
--Kyle Sluder
_______________________________________________
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