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

Converting from Carbon Event Manager to NSTimer


  • Subject: Converting from Carbon Event Manager to NSTimer
  • From: Dan Birns <email@hidden>
  • Date: Tue, 23 Sep 2008 16:20:29 -0700

I'm trying to convert from Carbon to Cocoa for a number of reasons which I won't go into here.

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.

In Carbon I'm using:

	EventLoopTimerUPP upp;
	upp = NewEventLoopTimerUPP(macTimerCallback);

	InstallEventLoopTimer(GetMainEventLoop(),0, kEventDurationForever,
						upp,0,&macTimer);
	

Then, when I need to set the timer:
	nextTimerTime = CFAbsoluteTimeGetCurrent() + nextTimer;
	SetEventLoopTimerNextFireTime(macTimer, nextTimer);

In Cocoa, the system I'm using requires me to allocate a new NSTimer every time I need to set a timer:

	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.

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];


This has failed. Investigating, I called [timer isValid] and it returns false. I've tried altering the args in various ways without success. I've also had various problems retain'ing this timer. When I add [timer retain];, it crashes having exhausted the stack, where it's calling retain over and over.

Help.

--Daniel
_______________________________________________

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


  • Follow-Ups:
    • Re: Converting from Carbon Event Manager to NSTimer
      • From: Uli Kusterer <email@hidden>
    • Re: Converting from Carbon Event Manager to NSTimer
      • From: Ken Thomases <email@hidden>
    • Re: Converting from Carbon Event Manager to NSTimer
      • From: Jason Coco <email@hidden>
  • Prev by Date: issues with mainMenu and initialization timing
  • Next by Date: IB's autosave column information vs. -setAutosaveTableColumns:
  • Previous by thread: issues with mainMenu and initialization timing
  • Next by thread: Re: Converting from Carbon Event Manager to NSTimer
  • Index(es):
    • Date
    • Thread