On Fri, May 2, 2008 at 3:13 AM, Graham Cox <[EMAIL PROTECTED]> 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to