Sign in to follow this  

weird cpu usage

This topic is 3591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am building a 2d game engine in with c# and direct3D and when I check the cpu usage of my programs using this engine I noticed something weird. When my application doesn't have focus the cpu usage jumps up to 50% and when it does have focus the cpu usage is 5% or lower. does anyone know what is causing this? Im using a peekmessage handler for my gameloop, maybe that is causing this, or it's just directX trying to get focus again or something like that. thanks in advance. id.

Share this post


Link to post
Share on other sites
Yup, could well be that your application is going into a very tight 'busy waiting' loop. It's not unreasonable or uncommon to put something like Sleep(10) into your loop when you're either minimized or inactive - play fair with the other applications and all that [wink]

The other common one is with some apps that change the timer frequency (media players tend to do this) so you can actually get a performance boost by having WMP running at the same time as your app [lol]

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
It's not unreasonable or uncommon to put something like Sleep(10) into your loop when you're either minimized or inactive - play fair with the other applications and all that [wink]


thanks I'll try that.

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
The other common one is with some apps that change the timer frequency (media players tend to do this) so you can actually get a performance boost by having WMP running at the same time as your app [lol]

hth
Jack


So if i was 2 run something like Crysis with Win Media Player on, it would give me a performance boost?

Share this post


Link to post
Share on other sites
Quote:
Original post by Firecore
Quote:
Original post by jollyjeffers
The other common one is with some apps that change the timer frequency (media players tend to do this) so you can actually get a performance boost by having WMP running at the same time as your app [lol]

hth
Jack


So if i was 2 run something like Crysis with Win Media Player on, it would give me a performance boost?


I doubt it. :p


Something you could also do is when you go inactive call WaitMessage when there are no messages, this will of course completely suspend your game when it's out of focus, but you'll use zero CPU. ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by Firecore
So if i was 2 run something like Crysis with Win Media Player on, it would give me a performance boost?
Something like Crysis would be designed to do the same thing that WMP does. All that media player does is override the default timing interval to be more accurate, your app can do this as well but by default most people don't bother.

It would be nice if there were a MakeApplicationFaster() function [smile]

Jack

Share this post


Link to post
Share on other sites

This topic is 3591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this