On Jul 30, 2013, at 08:54 , Vincent Habchi <vi...@macports.org> wrote:

> The way SQLite works, after a query is submitted, the thread is suspended and 
> a callback is repeatedly executed

There's one other consideration, in the case when the callback is called a 
thread other than the main thread, from non-ObjC code. You should also ensure 
that there's an autorelease pool in place, especially when using ARC (which may 
invoke 'autorelease' at times you can't easily predict).

Thus, I would advocate an approach based on the one Jean-Daniel mentioned 
earlier in the thread: move the code that does the actual work needed in the 
callback to a separate *method*, but hide your housekeeping -- the ugly bits -- 
in the function itself:

        static int MyCallback (void* context) { // assuming the parameter is 
just the object pointer
                @autoreleasepool {
                        int result = [(__bridge MyClass*) context 
myCallbackMethod];
                        return result;
                }
        }

In the case where the context is actually a structure containing the object 
pointer, then I'd retrieve it in this function (and likely all the other 
structure members, to pass as arguments to the method, unless there are an 
awful lot of them) so that the method can be written cleanly using normal ObjC 
conventions.

_______________________________________________

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

This email sent to arch...@mail-archive.com

Reply via email to