#### Archived

This topic is now archived and is closed to further replies.

# Loops?

This topic is 5819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I''m wondering if anyone has a solution for the following problem: Under Windows operating system we all (?) use tight loops to increase the number of frames per seconds. This will make sure that we have all the available CPU power we can get. If I for some reason want a frame rate about 50, I''ll have to halt my process for some time by waiting in a while-loop. How can I release the CPU under this time and allow it to run other processes or threads? I''ve tried to use some sort of thread-waiting-sleep-event solution but because of Windows it will only get me low fps (32 or so but no pressure on the CPU).

##### Share on other sites
This is problematic, and not sure there is any good solution. But, I think there is a function that just gives up your time-slice (no sleeping/waiting) and acts like your thread's time was up. I think it should only be around a few ms before you get the CPU again. You could make a clever (wait) loop, that will remember how long it took for you to get back control, and only give back the CPU if it's more than that time left to wait. You could also mess with raising the priority of the process.

EDIT: I just threw together something to show what sort of loop I meant. What the realm name of "GiveBackControlToWindows()" is, I don't remember.
dwNextFrameTick = dwLastFrameTick + dwFrameTickCount;dwTicksToGetBack = 0;while((dwCurrentTick = GetTickCount()) < dwNextFrameTick) {    if(dwTicksToGetBack < (dwNextFrameTick - dwCurrentTick))        GiveBackControlToWindows();    dwTicksToGetBack = GetTickCount() - dwCurrentTick;}

[edited by - CWizard on October 19, 2002 7:29:50 AM]

##### Share on other sites
The standard Win32 API timer functions only fires a message once every 18th of a second.

You probably need to play with the kernel-level timer. Check out:

http://www.bitbanksoftware.com/Programmers/code4.html

HTH

--
Sean Timarco Baggaley

[edited by - stimarco on October 19, 2002 7:45:33 AM]

##### Share on other sites
CWizard, the name of the function you did not remember is Sleep The call
Sleep(0)
"causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run." (MSDN Library)

##### Share on other sites
quote:
Original post by EliasAE
CWizard, the name of the function you did not remember is Sleep The call
Sleep(0)
"causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run." (MSDN Library)
Hmm, probably it was that, although I thought I remember it having a more cryptic name. But, it''s probably Sleep(0), which should allow you to do what you want, if you do it clever.

##### Share on other sites
I thought I remembered something different too. I just can''t seem to find it. OTOH, i''ve programmed in so many different languages, environments, and IDEs, I may be thinking of one of those.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 16
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632659
• Total Posts
3007692
• ### Who's Online (See full list)

There are no registered users currently online

×