Re: NSTimer or what?
Re: NSTimer or what?
- Subject: Re: NSTimer or what?
- From: Alastair Houghton <email@hidden>
- Date: Tue, 20 Jun 2017 10:24:16 +0100
On 20 Jun 2017, at 04:04, Gerriet M. Denkmann <email@hidden> wrote:
>
> macOS 11+
>
> Some Cocoa app which has to do:
> 1. something a few seconds later
The main issue here isn’t energy use so much as whether you want to be able to
cancel the operation. If you need to be able to cancel it before it fires,
you’ll want to use NSTimer or a CFRunLoopTimer. Energy wise, the fact this is
to happen “a few seconds later” would seem to imply that it isn’t going to
happen often, so it’s probably irrelevant and which you choose is a matter of
taste.
> 2. some other thing repeatedly about every 0.1 second.
Personally, I’d choose an API that directly supports repeating timers, so I’d
prefer NSTimer or CFRunLoopTimer over the other options, all else being equal.
I’d imagine that’s most likely to result in the lowest energy usage (repeated
use of one-shot timers, it seems to me, is much more likely to result in
dynamic memory allocation happening every time the timer fires, and it’s more
complicated in your code because you’ll have to manage your next fire time).
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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