Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » 90% CPU usage Allegro Function

This thread is locked; no one can reply to it. rss feed Print
90% CPU usage Allegro Function
thirdy
Member #8,409
March 2007
avatar

When I use this function set_display_switch_mode(SWITCH_BACKGROUND); my program uses an average of 90% cpu usage. But it doesn't actually make my computer slow when running the program. But this is not good right?

CGamesPlay
Member #2,559
July 2002
avatar

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

GullRaDriel
Member #3,861
September 2003
avatar

First: set_display_switch_mode is not using 90% cpu. The rest of your code is using them.

set_display_switch_mode(SWITCH_BACKGROUND) only tells the OS that your program should not be paused when it looses focus.

Eating all the CPU is not each time bad. You can use less cpu by using rest in your main loop.

EDIT: can we consider that you beat me , CGamesPlay ? :P

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

thirdy
Member #8,409
March 2007
avatar

Oh yeah your right. My program only uses 90% cpu when it is running/active

Kris Asick
Member #1,424
July 2001

The CPU graph is more or less how much of your CPU's total power is being used to process stuff. There's nothing wrong with using 100%, it simply means that your CPU is going full throttle. The only bad thing about reaching 100% is that more CPU time is being requested than is available, so it starts getting portioned out in smaller quantities to all running processes and threads to balance it out between them by priority. Thus once you hit 100%, your program will no longer be able to maintain it's usual framerate if you add more processing to its main loop.

You can still hit 100% CPU usage using rest(0) or Sleep(0) in your Allegro driven program. It simply means your program is using a lot of CPU time to do its thing.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

thirdy
Member #8,409
March 2007
avatar

My program has a countdown timer, and it has to countdown even if my program is not active. I'm using clock(); from timer.h which returns cpu CLOCKS_PER_SEC. Will using rest(100) or other function that will reduce the 90% CPU usage affect the precision of one second in the coundown timer?

Go to: