Sign in to follow this  
frozen_hell1618

cpu

Recommended Posts

Guest Anonymous Poster   
Guest Anonymous Poster
Unless you have added a blocking operation that uses some kind of sleep() routine, your code will run as fast as possible no matter what the complexity and so use 100% cpu

Share this post


Link to post
Share on other sites
jbadams    25677
Those tutorials rely on looping the rendering code over and over so that the screen is continuously updated. Therefore, unless you specifically tell the operating system to give other programs a turn, you will use 100% of the CPUs capacity.

Share this post


Link to post
Share on other sites
purple_moon    122
On my computer when the tutorial is running at foreground, my CPU is at less than 10% (AMD Sempron 2200+, GeForce 5700). But when the window is minimized or all of its client area is covered by other windows, CPU is up to 100%. What's the deal??

Share this post


Link to post
Share on other sites
jbadams    25677
Quote:
Originally posted by frozen_hell1618
soo how todo, to use smaller code?another sugestion?

I think you probably mean faster or more efficient code, so that it won't be using 100% of the CPU resources, yes? That isn't actually the problem though, since you're running (one of the earlier?) NeHe tutorials it isn't really doing much, and so will be running quite efficiently. It is in fact doing exactly what it's supposed to do; nowhere in the code have you told it that it should surrender some of the CPU resources back to the operating system to assign to other tasks, so it's running the instructions it's been given as fast as it can.

As the AP suggested, one 'fix' for this that some people use is to ensure that the program is running above a certain desired framerate (you wouldn't want to use less resources if your game was already running too slow...), and if so sleep() for a certain amount of time.

Share this post


Link to post
Share on other sites
Spoonbender    1258
Quote:
Original post by frozen_hell1618
i need to call a interupt(eg.when the mouse mouves a interup is called) to pass cpu to other .exe??


Yes, if you're running something like DOS.
For the rest of us, no, you don't need to do *anything*

Try it for yourself. Does other applications freeze while your game is running? Does Winamp keep playing music?

Everything will be running fine, because your OS manages this for you. It ensures that every process gets an equal share of CPU. If a process yields the cpu before its time is up, there's some leftover cpu time, which is given to whicheer process can use it. In this case, that's your application.

You're not starving other processes of cpu time, you're just getting all the leftovers. And in your case, the "leftovers" amount to just under 100%.
So there isn't a problem.

Share this post


Link to post
Share on other sites

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