• 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: NSTimer Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimer Question


  • Subject: Re: NSTimer Question
  • From: Graham Cox <email@hidden>
  • Date: Mon, 16 Feb 2009 23:49:20 +1100


On 16 Feb 2009, at 11:44 pm, Andreas Grosam wrote:

how does a NSTimer object that has been setup with a repeating time interval calculate the time when it fires an event?

There may be two possibilities:
Say, the initial time is at t0, the interval is T, and the time when it fires the first event is at t1, the second at t2, etc.
The time when it fires the ith event will be ti:
A)
ti = t (i-1) + T


B)
ti = i * T + t0


Reason:
If I need a "tick" that corresponds to a current time, I would prefer method B (mean error remains stable).
In case A the firing time may fade away with respect to the initial time due to inherent inaccuracies. Although this error is certainly small compared to the error that we have when we measure the time when we actually do handle the event, but it may accumulate over a long duration. That is the error increases with time.


I may be wrong, but I believe it's A. Timers that get delayed for some reason (like a callback taking too long) do not attempt to compensate on subsequent firings.

If you need to accurately measure the elapsed time in a timer callback, don't assume, ask the system for it and measure it yourself.

--Graham




_______________________________________________

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: NSTimer Question
      • From: Andy Lee <email@hidden>
References: 
 >NSTimer Question (From: Andreas Grosam <email@hidden>)

  • Prev by Date: NSTimer Question
  • Next by Date: Re: NSTimer Question
  • Previous by thread: NSTimer Question
  • Next by thread: Re: NSTimer Question
  • Index(es):
    • Date
    • Thread