Thread: Program speed using time instead of memory

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    10

    Program speed using time instead of memory

    Is there a way that I can make my programs run at a constant speed? It speeds up and slows down spontaneously. I am using Turbo C++ 1.00.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    129
    There sure is, and I forget how.

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    in time.h and dos.h there are some time functions, check them out.

    Basically this is what you should do:

    loop {
    ...get time...
    ...do stuff....
    ...get time 2...
    ...compare times...
    }

    now lets say you want your program to run at a constant speed...then every time you go through the loop, compare the two times which you get. Lets say you want your program to run at a certain FPS (like in graphics) constantly. Then you want to set a constant amount of time in which you refresh....lets say you refresh every 40 milliseconds...

    then if "get time 2" was 40 milliseconds or greater than "get time", then you do stuff, otherwise you dont...

    this will make it run pretty constant
    My Website

    "Circular logic is good because it is."

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    10

    Question Which Functions?

    Does anybody know of a function in Turbo C++ 1.00 that can count time faster than a second? I looked through the functions in time.h and dos.h, but couldn't find anything.

    This is mainly to make graphics run at a constant speed.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    129
    Well, you could switch to djgpp+allegro, allegro has everything you could ever need for any kind of timing.
    flashdaddee.com rocks!!!

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    To do that you are either going to have to hook the clock tick interrupt or mess around with the PIT. For information on PIT programming check out www.peroxide.dk. For information on hooking the clock tick interrupt, check out the RBIL.

    NOTE: If the RBIL says do not hook the original timer interrupt then don't do it. If you do and forget to call the previous handler from your handler, your system time will be messed up. There is another interrupt that is also triggered every tick of the clock. This one is the one you should hook as it will not affect your system time.

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    10
    Peroxide.dk had no information about PIT that I could find, and I don't plan to switch to DJGPP. I tried to install it in the past, but all I did was waste 3 hours.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. time program showing time since epoch?
    By cus in forum Linux Programming
    Replies: 5
    Last Post: 01-10-2009, 01:56 PM
  2. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 02:38 PM
  3. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM
  4. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM
  5. worst time to program
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 06-10-2002, 11:32 PM