Thread: How do u control time in c++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Exclamation Sometimes non-portable code is better...

    but that eats up your CPU cycles like you wouldn't believe...
    RIGHT !!!

    This is an interesting case where it’s better to go with the non-standard code! Sleep(), etc., will release your CPU to do other stuff. Like major_small said, using the ISO/ANSI time functions will hog the CPU for the sole purpose of wasting time! This is BAD thing to do with a multitasking system.

    If possible, it’s better check if “loading” is actually complete than, to use a fixed 5-second delay. For example, you could use Sleep() in a loop and check it every half-second or so.

    BTW- I have a BASIC function: DelayDot(Delay, Count) that displays “Wait.......Count is the number of “dots”, and Delay is the time between “dots”. I’ve used it kinda-like a library function in several BASIC programs.

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by DougDbug
    This is an interesting case where it’s better to go with the non-standard code! Sleep(), etc., will release your CPU to do other stuff. Like major_small said, using the ISO/ANSI time functions will hog the CPU for the sole purpose of wasting time! This is BAD thing to do with a multitasking system.
    d00der... in this case it's not bad... if you want to make it look like your program's doing something, this is a good thing... and it's not the functions that are doing it, it's your semi-infinite loop that's eating the cycles... find a way to slow the loop and you've got a way to lower the amount of CPU cycles you're using up...

    Sleep() actually puts your program's thread into a sleep mode, where it can't do anything... but using the method I said, you can have your program "do that for 5 minutes"...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. last write time
    By pastitprogram in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2008, 06:54 PM
  2. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 07:11 AM
  5. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM