99% CPU Usage...

This is a discussion on 99% CPU Usage... within the Game Programming forums, part of the General Programming Boards category; Pacman doesn't count pall....

  1. #16
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Pacman doesn't count pall.

  2. #17
    |<o>| <--cyclopse LouDu's Avatar
    Join Date
    Mar 2003
    Posts
    137
    bah lol like DArk ages of camelot may be laggy but doesnt use 99%
    Languages <> C++, HTML

    /*The Ledgend of Ludlow Coming to a PC Near
    You intro Cinenmatic Needed email me of
    Reply to one of my threads if you can make
    one, thats decent. */

  3. #18
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I think you'll find sleeping for 1-10ms will stop your program from hogging the CPU. 60ms is too long when you're waiting for input.

  4. #19
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    LD:
    Code:
    int main()
    {
    int x=1;
    while(0==0)
    {
    x=x*x-2*x*5/x/x/x/x/x*x*x*x*x*-x-x-x+x/x;
    }
    return 0;
    Compile and run, it will take 99% CPU time regardless of the processor.

    SC: I had something similar to that, but it takes 99% and has the non moving problem.

    TD: I'm using SDL, I'm not sure about VSync...

    [edit]
    Eibro: Just saw your post after I posted. Yeah, 60 ms is way to long, but if I go really low than you have to tap the button really fast otherwise it moves multiple times
    [/edit]

    //napKIN
    Last edited by napkin111; 03-02-2003 at 07:22 PM.
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Donít just wait for The Right Thing to strike you Ė try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  5. #20
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Originally posted by LouDu
    most large games dont even useup 99% cpu usage even when i play online
    Hogging 99% of the CPU time is much different from using 99% of the CPU's processing power.
    Napkins program is probably doing nothing 98.9% of the time that its hogging the CPU.

  6. #21
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Originally posted by Eibro
    Hogging 99% of the CPU time is much different from using 99% of the CPU's processing power.
    Napkins program is probably doing nothing 98.9% of the time that its hogging the CPU.
    Correct...well, I guess it IS going through the loop really fast checking for input...

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Donít just wait for The Right Thing to strike you Ė try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  7. #22
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    [edit]
    Eibro: Just saw your post after I posted. Yeah, 60 ms is way to long, but if I go really low than you have to tap the button really fast otherwise it moves multiple times
    [/edit]
    Don't lose your other construct for timing your program. Combine the two like this:
    Code:
    while (true)
    {
        if (lastupdate + 60 < SDL_GetTicks())
        {
             // Gamecode
             lastupdate = SDL_GetTicks();
        }
        SDL_Delay(5/* 1 to 10 */);
    }
    Let me know if that works, I didn't test it.
    Edit: Heh, 1000th post.

  8. #23
    |<o>| <--cyclopse LouDu's Avatar
    Join Date
    Mar 2003
    Posts
    137
    is the code orginzationn in codein really super inportant?
    Languages <> C++, HTML

    /*The Ledgend of Ludlow Coming to a PC Near
    You intro Cinenmatic Needed email me of
    Reply to one of my threads if you can make
    one, thats decent. */

  9. #24
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Originally posted by LouDu
    is the code orginzationn in codein really super inportant?
    Very. It is extremely important when you go back to look at code.

    Oh, and its important if you want your program to work too heh.
    Code:
    }
    return 0;
    int main()
    cout<<"hello world!";
    #include <iostream.h>
    {
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Donít just wait for The Right Thing to strike you Ė try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  10. #25
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Thanks Eibro, through a bit of experimentation it works great and takes up an average of 60% CPU (on a 1.6 P4). I really appreciate all the help I receive on this board, thanks!

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Donít just wait for The Right Thing to strike you Ė try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  11. #26
    |<o>| <--cyclopse LouDu's Avatar
    Join Date
    Mar 2003
    Posts
    137
    Originally posted by Eibro
    Hogging 99% of the CPU time is much different from using 99% of the CPU's processing power.
    Napkins program is probably doing nothing 98.9% of the time that its hogging the CPU.
    ohh ok thanks
    Languages <> C++, HTML

    /*The Ledgend of Ludlow Coming to a PC Near
    You intro Cinenmatic Needed email me of
    Reply to one of my threads if you can make
    one, thats decent. */

  12. #27
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    It is probably your main loop as the PeekMessage() is a CPU hog as it keeps pumping the msg que until there is a message (as opposed to GetMessage() which waits until there is a msg ).


    >>I think you'll find sleeping for 1-10ms

    without using a high resolution timer you must expect a +/-5ms delay in all timers. This is due to them being very low priority in the msg que and a bug in MS OS's (there is a patch available but don't think your user will have it)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  13. #28
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Ah, thankyou. When I get home I will look into GetMessage(). That sound more like what I'm looking for.

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Donít just wait for The Right Thing to strike you Ė try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reduce CPU usage
    By patrick22 in forum Windows Programming
    Replies: 9
    Last Post: 07-10-2009, 03:13 PM
  2. questions on multiple thread programming
    By lehe in forum C Programming
    Replies: 11
    Last Post: 03-27-2009, 08:44 AM
  3. Net cpu usage of pthreads?!
    By mynickmynick in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2008, 08:59 AM
  4. Calculating CPU Usage
    By vitaliy in forum Linux Programming
    Replies: 3
    Last Post: 08-21-2005, 10:38 AM
  5. CPU Usage so high
    By X PaYnE X in forum Windows Programming
    Replies: 9
    Last Post: 12-21-2003, 03:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21