Skip to main content
GameDev.net gamedev.net
🔒 Locked

== 100% CPU usage ==

Started by TheHighKing Mar 12, 2003 at 6:21 PM 12 replies 850+ views
Original Post
TheHighKing
TheHighKing
... so when I start my applications (using D3D 8 ) the CPU usage jumps to 100% from 2-3% (My PC have P3-866MHz with 256RAm/133MHz and 64MB nVidia GF2 MX400 videocard W2K prof.)This is no matter what is on the screen or even an empty D3D window (fullscreen or windowed)??? I''m using source code from nexe.gamedev.net -tutorials to make my D3D window . So any ideas ??? ===================== regard:TheHighKing BG
=====================regard:TheHighKing BG
JoeyBlow2
JoeyBlow2
Thats normal, you are probably in a tight loop. The logic is probably like this:

If no windows messages, render. Loop.

You will always be calling the render functions as long as there are no windows messages. The function will still be called over and over again, as fast as the computer can go... That will take 100% cpu. Unless you specifically put code in there to tell the computer to slow down, it won''t.

Running windows normally takes 2-3% because its saying "Do nothing until the mouse moves or someone touches the keyboard, or we get a network packet"...

If you want to do something similar, you need to put code in there. Make i tmore like this:

If no window messages, and something needs to be rendered then render, otherwise sleep. Loop.

Nerusai
Nerusai
If it eats to much CPU you can try implement a Sleep ( 1 ) in the continuous loop.
---Yesterday is history, tomorrow is a mystery, today is a gift and that's why it's called the present.
The Frugal Gourmet
The Frugal Gourmet
I find that this is almost always the case, but you can still run other programs just fine.

Co-creator of Star Bandits -- a graphical Science Fiction multiplayer online game, in the style of "Trade Wars'.
mohamed adel
mohamed adel
The cpu usage never jumps to 100 at all. the wndproc method of geting what''s in the computer queue and then rendering never causes this.There''s an error in your code or you are performing so many calculations that can''t be done in real time (calculating surface deformations for a big no. of vertices or something like that) and I don''t think you are doing so.try to find out what''s wrong with your code or send it so you can have more helpful answer.
TheHighKing
TheHighKing
Thanks to all of you gals & pals
1) [JoeyBlow2,Siaon] When I use sleep(1) the CPU usage for the thread of my program goes ~0% (I still haven''t measured the FPS )and everything looks to be in order.
2) [Anonymous Poster] yes I''m using the software processing of the veteces so what ???
3) [The Frugal Gourmet] if some program like WinAmp is active before execution of my exe it works fine but it is hard even to move the mouse pointer
4) [mohamed adel] but the same problem appears even if I use a empty D3D window (with no graphic to render).But if the infinite loop that I use uses my system as fast as possible and makes more FPS than are needed -- this is error code
P.S. I havn''t even imagine that 1 m.sec. on every loop is the distance between 99% and 100% :/
~ Thx again ~

=====================
regard:TheHighKing BG
=====================regard:TheHighKing BG
Link
Link
how work Sleep ( 1 ) ??
aftermath
aftermath
quote:
Original post by Link
how work Sleep ( 1 ) ??



    
/* ... code ... */
Sleep(1);
/* ... more code ... */


edit: horray! faster posting times!

[edited by - aftermath on March 13, 2003 6:10:18 PM]
Rate me up.
TheHighKing
TheHighKing
"...The Sleep function suspends the execution of the current thread for the specified interval.
...
VOID Sleep(
DWORD dwMilliseconds // sleep time
);
..." part of ''Platform SDK: DLLs, Processes, and Threads'' topic in D3D9 SDK helpfiles

=====================
regard:TheHighKing BG
=====================regard:TheHighKing BG
null_vector
null_vector
Sleep(1) gives windows' thread management at opportunity to interrupt you process. Its not a matter of how long it sleeps, just the fact that you've said to windows, "hey i'm not doing anything right now".

I assume you are writing a fullscreen game, therefore what does it matter if you're using 100% of the processor. Nothing else should be running.

If all else fails lock your render loop to only render every 1/30 of a second.

[edited by - null_vector on March 14, 2003 9:42:42 AM]
find / -name "your base" -exec chown -R us:us {} ;
Link
Link
my game update the screen every loop (frame), where do u suggest to dispose Sleep(1)?
TheHighKing
TheHighKing
You can perform a check each time before to call your draw function how many FPS you are using and eventual use the Sleep(...) function.Or just call it there

=====================
regard:TheHighKing BG
=====================regard:TheHighKing BG
q2guy
q2guy
you can do Sleep(0) like it is told in msdn or WaitMessage()

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.