Sleep();

This is a discussion on Sleep(); within the Windows Programming forums, part of the Platform Specific Boards category; Use something like clock() or GetTickCount() or, more precise, timeGetTime(). Just take a value when you begin and then take ...

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    Use something like clock() or GetTickCount() or, more precise, timeGetTime().
    Just take a value when you begin and then take one value when you stop and subtract and you have the time it took to execute.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114
    Thanks, ill try it out.

  3. #18
    Registered User
    Join Date
    Feb 2008
    Posts
    12
    Quote Originally Posted by Elysia View Post
    Use something like clock() or GetTickCount() or, more precise, timeGetTime().
    Just take a value when you begin and then take one value when you stop and subtract and you have the time it took to execute.
    I don't get it, how do I take a value?

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    Code:
    DWORD dwTick1 = timeGetTime();
    // Do stuff
    DWORD dwTime = timeGetTime() - dwTick1;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Feb 2008
    Posts
    12
    Oh thanks
    EDIT
    Code:
      [Linker error] undefined reference to `timeGetTime@0'
    Last edited by HelpLol; 02-17-2008 at 07:33 PM.

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    Link with Winmm.lib.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Feb 2008
    Posts
    12
    Quote Originally Posted by Elysia View Post
    Link with Winmm.lib.
    Sorry about this... How?

  8. #23
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    Depends on IDE. But add under additional libraries or linker input libraries or some such.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Registered User
    Join Date
    Feb 2008
    Posts
    12
    oh thanks. Got it working.

  10. #25
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > Sleep can also sleep less than the specified interval in some cases. But it sleeps roughly the amount of time specified by the code. And of course you can pass a variable with the time to the function.

    Cool, very helpful -- I always thought Sleep() was guaranteed to sleep for at least n seconds. Apparently not.

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

Similar Threads

  1. [pthread] cancellable sleep in win32?
    By cyberfish in forum C++ Programming
    Replies: 2
    Last Post: 08-11-2007, 02:30 AM
  2. Sleep works with just one thread, but not 2
    By finkus in forum C++ Programming
    Replies: 5
    Last Post: 12-01-2005, 08:17 PM
  3. Problem with Sleep() #$@^#$%^
    By intruder in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 06:46 AM
  4. why do we require sleep?
    By jinx in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 07-14-2004, 08:21 AM
  5. Sleep is overrated...
    By Polymorphic OOP in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 01-24-2003, 11:40 AM

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