Simple program overloads CPU |
Naith
|
In the end of the mainloop of your application (after 'SDL_RenderPresent(renderer);'), add 'SDL_Delay(1);'.
This will allow the processor to take a break from your application and do something else, which will limit the processor usage on your application. I couldn't see anything in your code that would cause high CPU-usage though. |
|||||||||||
|
Blaze
|
Thank you, it now runs with <0% CPU usage. For the future, will setting a maximum framerate be a working alternative to using SDL_Delay()?
|
|||||||||||
|
Naith
|
Not sure I understand your question correctly.
Whenever you wanna do a frame-rate cap function, you normally set a maximum frame-rate (60 FPS for example) and then use SDL_Delay to limit the frame rate to be <= to 60 FPS. If you don't wanna have such function, you can always create your program with VSync enabled but you won't be able to set the FPS you want and the highest FPS will instead be set to your monitor's refresh rate. Both of this alternatives will indeed limit the processor usage on your program. |
|||||||||||
|
Blaze
|
Okay, I understand. Thank you
|
|||||||||||
|