Click here to Skip to main content
15,917,875 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Windows Mobile 5 / C++ simple question / begging Pin
Iain Clarke, Warrior Programmer15-Jan-07 7:12
Iain Clarke, Warrior Programmer15-Jan-07 7:12 
GeneralRe: Windows Mobile 5 / C++ simple question / begging Pin
Polity4h15-Jan-07 13:22
Polity4h15-Jan-07 13:22 
GeneralRe: Windows Mobile 5 / C++ simple question / begging Pin
Rajesh R Subramanian15-Jan-07 18:09
professionalRajesh R Subramanian15-Jan-07 18:09 
GeneralRe: Windows Mobile 5 / C++ simple question / begging Pin
Iain Clarke, Warrior Programmer15-Jan-07 22:31
Iain Clarke, Warrior Programmer15-Jan-07 22:31 
GeneralRe: Windows Mobile 5 / C++ simple question / begging [modified] Pin
Rajesh R Subramanian15-Jan-07 22:37
professionalRajesh R Subramanian15-Jan-07 22:37 
GeneralRe: Windows Mobile 5 / C++ simple question / begging Pin
Iain Clarke, Warrior Programmer16-Jan-07 3:55
Iain Clarke, Warrior Programmer16-Jan-07 3:55 
QuestionCreate DLL Single Document Application Pin
sdancer7515-Jan-07 5:25
sdancer7515-Jan-07 5:25 
QuestionGoing Loopy Pin
Waldermort15-Jan-07 4:52
Waldermort15-Jan-07 4:52 
I have taken a stab at creating my own high-res timer class. It works by launching a thread which queries the high performance counter and calls a callback when when the event is triggered. The trouble is it uses a lot of the CPU's idle time when looping. The full thread callback follows, I wonder if anybody could suggest a way to decrease the CPU usage.
UINT CTimer::ThreadProc( LPVOID pParam )
{
    LPTIMERDATA tData = (LPTIMERDATA)pParam;

    EnterCriticalSection( &m_csLock );

    LARGE_INTEGER  lilastTime = m_liStartTime;
    UINT_PTR       uIdEvent   = tData->uIdEvent;
    UINT           uSleepTime = tData->uSleepTime;
    HWND           hWnd       = tData->hWnd;

    LeaveCriticalSection( &m_csLock );

    LARGE_INTEGER  liCurrentTime;
    BOOL           bIsActive  = TRUE;

    do
    {
        QueryPerformanceCounter( &liCurrentTime );
        double dMilliSecs = ( (double)liCurrentTime.QuadPart - (double)lilastTime.QuadPart );
        dMilliSecs /= (double)m_liFrequency.QuadPart;
        dMilliSecs *= 1000;

        if ( (UINT)dMilliSecs % uSleepTime == 0 )
            TimerProc( hWnd, WM_TIMER, uIdEvent, GetTickCount() );

        EnterCriticalSection( &m_csLock );

        uSleepTime = tData->uSleepTime;
        bIsActive  = tData->bIsRunning;

        LeaveCriticalSection( &m_csLock );

        Sleep(0);

    } while( bIsActive );

    _endthreadex( 1 );

    return 0;
}


Also I test for the even using if ( (UINT)dMilliSecs % uSleepTime == 0 ) I'm worried this would miss a beat.
AnswerRe: Going Loopy Pin
Roger Stoltz15-Jan-07 5:34
Roger Stoltz15-Jan-07 5:34 
GeneralRe: Going Loopy Pin
Waldermort15-Jan-07 6:49
Waldermort15-Jan-07 6:49 
QuestionHow to fastly write huge array or list to file ? Pin
Michael_Lotfy15-Jan-07 2:44
Michael_Lotfy15-Jan-07 2:44 
AnswerRe: How to fastly write huge array or list to file ? Pin
#realJSOP15-Jan-07 3:23
professional#realJSOP15-Jan-07 3:23 
AnswerRe: How to fastly write huge array or list to file ? Pin
Joe Woodbury15-Jan-07 6:10
professionalJoe Woodbury15-Jan-07 6:10 
QuestionAre The libmysql.lib error is system specific Pin
Y_Kaushik15-Jan-07 2:40
Y_Kaushik15-Jan-07 2:40 
AnswerRe: Are The libmysql.lib error is system specific Pin
prasad_som15-Jan-07 2:53
prasad_som15-Jan-07 2:53 
QuestionShell Extensions - Vista 64 Bit Pin
Tony Teveris15-Jan-07 2:38
Tony Teveris15-Jan-07 2:38 
QuestionDLL size Pin
PatrykDabrowski15-Jan-07 2:06
PatrykDabrowski15-Jan-07 2:06 
AnswerRe: DLL size Pin
mark novak15-Jan-07 2:28
mark novak15-Jan-07 2:28 
GeneralRe: DLL size Pin
PatrykDabrowski15-Jan-07 2:41
PatrykDabrowski15-Jan-07 2:41 
AnswerRe: DLL size Pin
#realJSOP15-Jan-07 3:25
professional#realJSOP15-Jan-07 3:25 
AnswerRe: DLL size Pin
David Crow15-Jan-07 3:28
David Crow15-Jan-07 3:28 
GeneralRe: DLL size Pin
PatrykDabrowski15-Jan-07 3:47
PatrykDabrowski15-Jan-07 3:47 
QuestionRe: DLL size Pin
David Crow15-Jan-07 3:54
David Crow15-Jan-07 3:54 
GeneralRe: DLL size Pin
PatrykDabrowski15-Jan-07 3:58
PatrykDabrowski15-Jan-07 3:58 
AnswerRe: DLL size Pin
jonny515-Jan-07 11:53
jonny515-Jan-07 11:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.