Board index » delphi » delay procedure & time of cpu (BP7)

delay procedure & time of cpu (BP7)

Why following procedure takes so much of time of cpu?
Under WinNT this process occupies 100% of processor!
 How this to eliminate or to minimalize?

 Procedure Delay(ms : LongInt);
Var TickCount : LongInt;
    M         : TMsg;
Begin
 TickCount := GetTickCount;
 While GetTickCount - TickCount < ms do
 If PeekMessage(M,0,0,0,pm_Remove) then
  Begin TranslateMessage(M); DispatchMessage(M);End;
End;

empeka

 

Re:delay procedure & time of cpu (BP7)


why dont you just use the delay() procedure supplied in the CRT unit?
Quote
empeka <emp...@alpha.net.pl> wrote in message

news:EPQ94.9077$W3.217270@news.tpnet.pl...
Quote
> Why following procedure takes so much of time of cpu?
> Under WinNT this process occupies 100% of processor!
>  How this to eliminate or to minimalize?

>  Procedure Delay(ms : LongInt);
> Var TickCount : LongInt;
>     M         : TMsg;
> Begin
>  TickCount := GetTickCount;
>  While GetTickCount - TickCount < ms do
>  If PeekMessage(M,0,0,0,pm_Remove) then
>   Begin TranslateMessage(M); DispatchMessage(M);End;
> End;

> empeka

Re:delay procedure & time of cpu (BP7)


Re:delay procedure & time of cpu (BP7)


U?ytkownik R.Ossowski <r...@bitstorm.net> w wiadomo?ci do grup dyskusyjnych
napisa3:FvT94.5699$GS5.17...@newsfeed.slurp.net...

Quote
> why dont you just use the delay() procedure supplied in the CRT unit?

Because my programm is compiled under windows ,
not real or protected

Re:delay procedure & time of cpu (BP7)


Re:delay procedure & time of cpu (BP7)


In <FvT94.5699$GS5.17...@newsfeed.slurp.net>, "R.Ossowski" <r...@bitstorm.net> writes:

Quote
>why dont you just use the delay() procedure supplied in the CRT unit?
>empeka <emp...@alpha.net.pl> wrote in message
>> Why following procedure takes so much of time of cpu?
>> Under WinNT this process occupies 100% of processor!
>>  How this to eliminate or to minimalize?

  One reason for not using the Delay routine supplied in the
CRT unit is that it assumes it has the processor all to itself
(in addition to the famous 'Divide By Zero (#200)' bug when
CRT unit initializes the delay count on fast systems.)

  To resolve the CPU hogging for long delays, try releasing
timeslices to the operating system if >0.1 seconds to go.
Under the Windows 3.1 library, the procedure was called
'yield' and took no parameters.  The loop will need to be
modified to take into account the fact that the next CPU
timeslice the program gets might be at an unknown later
time. (especially if several other windows are also open)
  You might have to ask the OS for the time-of-day to
stabilize the loop's length which in turn can make your
computer's clock 'run slow' due to a bug within Microsoft's
code.

Other Threads