Just try the simple code I supplied with a 1, 2, second update time.  If you 
find that it doesn’t work, it’s 5 minutes spent.  If you find that it does, 
just figure out the update time that you want.  1/2 a second?  1/10 of a second?

The other thing you can have is a “hasTheDataChanged” setting and only proceed 
to check on the next update time throttle if the data has changed.
 
It’s akin to a dirty bit on a file.

CoreData does that with a hasUpdated or hasBeenUpdated setting so you don’t 
need to resave data needlessly.



> On Oct 23, 2020, at 10:51 AM, Andreas Falkenhahn <andr...@falkenhahn.com> 
> wrote:
> 
> The problem with that approach is that I'd need to find out the monitor's 
> refresh rate in order to calculate "nextUpdateTime" and I'm not sure if I can 
> get this information from all monitors reliably.
> 
> On 19.10.2020 at 00:09 Alex Zavatone wrote:
> 
>> It shouldn’t be too hard to roll your own simply based on milliseconds of a 
>> timer.
> 
>> Even a simple 
> 
> if (myMilliseconds >> nextUpdateTime) {
>>    [updateObject doThatUpdate];    
>>    nextUpdateTime = myMilliseconds + msThrottle;
>> }
> 
>> lets you get a basic throttle.
>> 
>> Cheers, 
>> Alex Zavatone
> 
>>> On Oct 15, 2020, at 2:13 PM, Andreas Falkenhahn via Cocoa-dev 
>>> <cocoa-dev@lists.apple.com> wrote:
> 
>>> I'm drawing inside an NSView by simply setting its layer's contents to a 
>>> CGImage which is updated for every frame, e.g. something like this:
> 
>>>      dp = CGDataProviderCreateWithData(NULL, frameBuf, frameBufSize, NULL);
>>>      im = CGImageCreate(frameWidth, frameHeight, 8, 32, frameStride, 
>>> theColorSpace, (CGBitmapInfo) kCGImageAlphaNoneSkipFirst, dp, NULL, FALSE, 
>>> kCGRenderingIntentDefault);
> 
>>>      view.layer.contents = (id) im;
>>>      CGImageRelease(im);
>>>      CGDataProviderRelease(dp);
> 
>>> This works fine except that there is no throttle so this will draw as fast 
>>> as the CPU allows, which of course is a waste of CPU cycles because the 
>>> monitor only refreshes a certain amount of times per second.
> 
>>> So is there a convenient way to throttle drawing to the monitor's refresh 
>>> rate or does this have to be done the hard way by querying the monitor's 
>>> refresh rate and then setting up a timer which draws in exactly those 
>>> refresh intervals or how should this be done?
> 
>>> Note that I'd like to avoid using OpenGL or Metal or whatever is the 
>>> standard nowadays but I'm mainly interested in an AppKit solution...
> 
>>> -- 
>>> Best regards,
>>> Andreas Falkenhahn                          mailto:andr...@falkenhahn.com
> 
>>> _______________________________________________
> 
>>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
>>> 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:
>>> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
>>> This email sent to z...@mac.com
> 
> 
> 
> 
> -- 
> Best regards,
> Andreas Falkenhahn                            mailto:andr...@falkenhahn.com
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to