Board index » delphi » Yet another CRT-unit bug?

Yet another CRT-unit bug?

I'm encountering strange problems with a BP7-program: when I include a
keypressed-function-evaluation in a loop it starts fine, but after a few
seconds of running, the program slows down extremely. From some quick
tests it seems that this problem occurs on a 2GHz machine, but not on 1
GHz. Also, I noticed that the problem disappeared when I changed the
internal mathematical calculations from double's to ordinary real's (the
calculation using real's is a lot slower it seems, something I didn't
expect either). The program does not give any errors on compiling or
running. Is there something strange happening when the
keypressed-function is called too often in a given amount of time?
 

Re:Yet another CRT-unit bug?


Quote
In article <3EAD3BF5.8020...@wxs.nl>, Dave Langers wrote:
> I'm encountering strange problems with a BP7-program: when I include a
> keypressed-function-evaluation in a loop it starts fine, but after a few
> seconds of running, the program slows down extremely. From some quick
> tests it seems that this problem occurs on a 2GHz machine, but not on 1
> GHz. Also, I noticed that the problem disappeared when I changed the
> internal mathematical calculations from double's to ordinary real's (the
> calculation using real's is a lot slower it seems, something I didn't
> expect either). The program does not give any errors on compiling or
> running. Is there something strange happening when the
> keypressed-function is called too often in a given amount of time?

Such a loop is called "busy waiting". One keeps the processor busy with waiting for
a key (by iterating through the loop over and over again).

On more modern OSes than Dos this is resolved by either blocking calls or (more primitive) by
giving up timeslices in the loop manually.

You could try to do this for dos also, using the various ways to give up a timeslice
(windows uses a int 2f call IIRC)

Re:Yet another CRT-unit bug?


JRS:  In article <3EAD3BF5.8020...@wxs.nl>, seen in
news:comp.lang.pascal.borland, Dave Langers <RemoveThisPart.d.langers@wx
s.nl> posted at Mon, 28 Apr 2003 16:34:29 :-

Quote
>I'm encountering strange problems with a BP7-program: when I include a
>keypressed-function-evaluation in a loop it starts fine, but after a few
>seconds of running, the program slows down extremely. From some quick
>tests it seems that this problem occurs on a 2GHz machine, but not on 1
>GHz. Also, I noticed that the problem disappeared when I changed the
>internal mathematical calculations from double's to ordinary real's (the
>calculation using real's is a lot slower it seems, something I didn't
>expect either). The program does not give any errors on compiling or
>running. Is there something strange happening when the
>keypressed-function is called too often in a given amount of time?

KeyPressed is in the Crt unit; the Borland Crt unit does not start above
200MHz or so; therefore it appears that you are using a modified system;
one wants to know _exactly_ what modifications are being used.

BP7 was written for DOS, but many faster machines use a DOS replacement
called Windows; if you are using such, one may need to know which, etc.

I think it likely that this is some sort of optimisation of scheduling,
imposed by Windows but not appropriate to the circumstances; if you are
running in a DOS box, or equivalent, it may be that PIF file changes, or
equivalent, are needed.

When using reals, which involve more CPU effort, it may be that I/O
appears less important, affecting timing policy.

This could be related to c.l.p.b. mFAQ 3.2.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
  <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
  <URL:http://www.merlyn.demon.co.uk/clpb-faq.txt>  RAH Prins : c.l.p.b. mFAQ;
  <URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.

Re:Yet another CRT-unit bug?


Quote
> Such a loop is called "busy waiting". One keeps the processor busy with waiting for
> a key (by iterating through the loop over and over again).

I'm not sure I understand you correctly, but in this case the structure
is like

repeat
   DoALotOfCalculations;
until (EndCalculations = TRUE) or KeyPressed;

The KeyPressed is used as an escape; KeyPressed also doesn't wait for a
keypress (like ReadKey does). So I'm not busy waiting, I'm busy
calculating. It seems to slow down almost to a stop when the loop is
iterated quickly enough for a while. When the KeyPressed function is
removed (or a slower PC is used) this doesn't happen.

I use WinME now, don't remember which crt-patch I used. I'm gonna try
running this under DOS to see if it is the timeslicing that causes this.

Re:Yet another CRT-unit bug?


Quote
In article <3EAE284F.5050...@wxs.nl>, Dave Langers wrote:
>> Such a loop is called "busy waiting". One keeps the processor busy with waiting for
>> a key (by iterating through the loop over and over again).

> I'm not sure I understand you correctly, but in this case the structure
> is like

> repeat
>    DoALotOfCalculations;
> until (EndCalculations = TRUE) or KeyPressed;

> The KeyPressed is used as an escape; KeyPressed also doesn't wait for a
> keypress (like ReadKey does). So I'm not busy waiting, I'm busy
> calculating.

Ok. The busy waiting algo is:

repeat
 <nothing>
until keypressed;

Quote
> It seems to slow down almost to a stop when the loop is iterated quickly
> enough for a while. When the KeyPressed function is removed (or a slower
> PC is used) this doesn't happen.

> I use WinME now, don't remember which crt-patch I used. I'm gonna try
> running this under DOS to see if it is the timeslicing that causes this.

Try to add a givetimeslice here and there. However long-term, specially if you keep using NT based
windows the only solution is to migrate to something win32. (Free Pascal, Delphi)

Other Threads