• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mixing Obj-C and C "methods"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mixing Obj-C and C "methods"


  • Subject: Re: Mixing Obj-C and C "methods"
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 30 Jul 2013 10:03:21 -0700

On Jul 30, 2013, at 08:54 , Vincent Habchi <email@hidden> 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 (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


References: 
 >Mixing Obj-C and C "methods" (From: Vincent Habchi <email@hidden>)
 >Re: Mixing Obj-C and C "methods" (From: Rick Mann <email@hidden>)
 >Re: Mixing Obj-C and C "methods" (From: Vincent Habchi <email@hidden>)
 >Re: Mixing Obj-C and C "methods" (From: Andy Lee <email@hidden>)
 >Re: Mixing Obj-C and C "methods" (From: Vincent Habchi <email@hidden>)

  • Prev by Date: Re: Getting a splash screen to show
  • Next by Date: Re: UIButton events on a CALayer
  • Previous by thread: Re: Mixing Obj-C and C "methods"
  • Next by thread: Re: Mixing Obj-C and C "methods"
  • Index(es):
    • Date
    • Thread