• 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: Converting from Carbon Event Manager to NSTimer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting from Carbon Event Manager to NSTimer


  • Subject: Re: Converting from Carbon Event Manager to NSTimer
  • From: Uli Kusterer <email@hidden>
  • Date: Wed, 24 Sep 2008 09:10:47 +0200

On 24.09.2008, at 01:20, Dan Birns wrote:
My application needs to set a timer that causes a function to be called at a time in the future. This is non-repeating, and sometimes has be immediate. I need it to be as efficient as possible, because it's called frequently.

Have you checked out the various performSelector: methods available? Particularly performSelector:withObject:afterDelay: seems to be a shorthand that might work much better. In any case though, watch out for Cocoa's run loop modes. By default, timers only get scheduled on NSDefaultRunLoopMode, so if you want your timer to also fire in NSModalPanelRunLoopMode or NSTrackingRunLoopMode (names from memory, may vary slightly), you may need to use the appropriate calls (the inModes: variant, or do an addTimer for the additional modes).


	self.timer = [NSTimer scheduledTimerWithTimeInterval:	t		// seconds
						  target:	self
						selector:	@selector (mainLoopTimer:)
						userInfo:	nil
						 repeats:	NO];

This is working fine, but our performance is poor. It's not so poor that it's obviously broken, but I'm looking for ways to improve it. I've been try to alloc one NSTimer that I reuse, and I've had no success doing so.

How did you measure this? What value is 't' ?

I've tried

timer = [NSTimer alloc];
[timer initWithFireDate:[NSDate date] interval:t target:self selector:@selector(mainLoopTimer:) userInfo:halTimer repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];

Why are you discarding the result of initWithFireDate:? You could be talking to the completely wrong object here. You really should use the ObjC [[NSClass alloc] init] idiom here, everything is engineered towards that, and timer is not guaranteed to be valid after the init call, you're supposed to re-set it to whatever the init returned.




Cheers, -- Uli Kusterer "The Witnesses of TeachText are everywhere..." http://www.zathras.de





_______________________________________________

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: 
 >Converting from Carbon Event Manager to NSTimer (From: Dan Birns <email@hidden>)

  • Prev by Date: Re: Rendering big PDF into thumbnail bitmap - too blurry
  • Next by Date: Re: How make a cocoa lib wich create a window ?
  • Previous by thread: Re: Converting from Carbon Event Manager to NSTimer
  • Next by thread: Re: Converting from Carbon Event Manager to NSTimer
  • Index(es):
    • Date
    • Thread