🔒 Locked
CPU usage
Advertisement
Original Post
Hi,
looking at most either commercial or otherwise finished products reveals that most of them have relatively low CPU usage (0 - 2%) - and I''m not talking about high-end games here. My programs, however, push this number up to 50-99% when using the standard program kernel - a simple do ... while(not_done) loop without any threading. How can I set my application''s priority in Windows'' priority queue?
Furthermore, can this be done in (Windows) console applications?
Thanks,
Crispy
its ok that your game uses up to 99% of CPU time. Take a look at games like Quake (Win95-version), Quake II, Quake III Arena, ... (not only id-software games). The clue is that these games reduce CPU usage when they are not currently active. in this case they suspend their thread by some time (and wait for incoming messages?). Take a look at the Q2-Source somewhere at ftp.idsoftware.com. In the file named sys_win.c should be some stuff to show how to suspend a thread by some time.
[edited by - sphinx23 on February 24, 2003 9:50:29 AM]
[edited by - sphinx23 on February 24, 2003 9:50:29 AM]
the point is the game loop:
while (1)
{
if (PeekMessage (...))
{
TranslateMessage
DispatchMessage
}
Update_Game ();
}
this game loop, in a whatever-you-want-to-have-game gives you ALWAYS 99% of CPU-Usage, because its a never exiting loop. Most, if not all, of today''s games (and most old) use this. What you possibly want to have is:
while (GetMessage (...))
{
TranslateMessage
DispatchMessage
}
This are the main loops app''s like ''notepad'' or the most of all out there use. they are not time-consuming, since they only react if a message is posted by windows or any other application
while (1)
{
if (PeekMessage (...))
{
TranslateMessage
DispatchMessage
}
Update_Game ();
}
this game loop, in a whatever-you-want-to-have-game gives you ALWAYS 99% of CPU-Usage, because its a never exiting loop. Most, if not all, of today''s games (and most old) use this. What you possibly want to have is:
while (GetMessage (...))
{
TranslateMessage
DispatchMessage
}
This are the main loops app''s like ''notepad'' or the most of all out there use. they are not time-consuming, since they only react if a message is posted by windows or any other application
CPU usage := 100 - time_spent_in_os_idle_loop / total_time
Even a low priority thread will eat up 100% CPU time if it can.
Guys, he''s talking about (console) apps.
For a Win app, you just use GetMessage; in a console app, you need to sleep periodically (Win32 and POSIX calls of the same name).
Example:
(only does stuff once a second => low CPU usage)
HTH
Jan
500x4
Even a low priority thread will eat up 100% CPU time if it can.
Guys, he''s talking about (console) apps.
For a Win app, you just use GetMessage; in a console app, you need to sleep periodically (Win32 and POSIX calls of the same name).
Example:
while(1)
check_input
...
sleep(1)
(only does stuff once a second => low CPU usage)
HTH
Jan
500x4
Thanks Jan - didn''t think of that. Works nice now. It''s just that some computers might have such applications as Prime95 (calculates Mersenne numbers), one of those cure-for-cancer type of programs and such running in the background and I don''t want my teeny weeny little console app to eat up all of the resources it can find (especially considering it doesn''t need them at all).
Crispy
grr@500
Crispy
grr@500
quote:
Original post by Jan Wassenberg
sleep(1)
(only does stuff once a second => low CPU usage)
sleep takes an arguement of milliseconds (in C/C++ anyway)
for (int i = 0; i < 21; i++) {
RequestPost();
cout << "Error 500" << endl;
Refresh();
}
Post();
cout << "No joke, it took this many tries!" << endl;
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement