Re: Work with AddressBook without blocking the main thread
Re: Work with AddressBook without blocking the main thread
- Subject: Re: Work with AddressBook without blocking the main thread
- From: Quincey Morris <email@hidden>
- Date: Sun, 26 Apr 2015 01:23:23 +0000
On Apr 25, 2015, at 17:54 , Peter Tomaselli <email@hidden> wrote:
>
> I don’t have a real good reason for not using the main thread at the moment—it seems fine, performance-wise, for what I am doing.
The point of these restrictions on ABAddressBook is that it’s *already* an asynchronous API. There’s no synchronous waiting that would block the main thread, and the fact that the completion handler is called on an “arbitrary” thread suggests that all the heavy lifting is already done on a background thread, outside of your control. For that reason, I can’t think of a reason why you’d ever want to start from a background thread.
Also, do you have a good reason for sticking with the C API? What about using the Cocoa API? [ABAddressBook sharedAddressBook] doesn’t seem to have the same-thread requirement, though [ABAddress addressBook] does.
(Note that in the current state of OS X or iOS, it’s a mistake to assume that the C version of an API is more performant than the Obj-C version. It’s almost always better just to use the one that’s easier to use, and that’s almost always the Obj-C version.)
> But I was interested in hearing if there was a more performant approach I might be missing, if only to satisfy my curiosity. Most of the info on the web about this is tons of GCD contortions that, from what I can tell, are missing the point.
>
> So with respect to spinning up a thread to “keep around”, just point me in the right direction here (this would be new stuff for me): is it NSThread I should look at?
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html <https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html>
However, there’s no reason to believe that using a background thread is going to perform better. All you’d be moving to the background thread, I think, is the creation of the ABAddressBookRef data structure itself, which isn’t going to make any difference to anything.
_______________________________________________
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