[fpc-pascal] When Pascal code is too fast

Marc Santhoff M.Santhoff at t-online.de
Thu Nov 1 09:05:02 CET 2007


Am Donnerstag, den 01.11.2007, 09:15 +0200 schrieb ik:
> On 11/1/07, Marc Santhoff <M.Santhoff at t-online.de> wrote:
> > Am Donnerstag, den 01.11.2007, 00:45 +0200 schrieb ik:
> > > Hi List,
> > >
> > > I have a weird problem. the "fpWrite" is too "slow" for FPC code. When
> > > I have the same exact code in C that writes a big amount of buffers of
> > > the same size with the same content. It seems that the fpWrite is way
> > > too fast, and the can't handle another call in the loop, and I need to
> > > slow down the loop using usleep.
> > > At the beginning I thought that it was a problem with fpWrite, so I
> > > created my own binding, but still the problem is the same.
> > >
> > > Except then the fact that it seems that FPC is much faster the GCC,
> > > any other ideas for such a behavior and what might be the reasons for
> > > it ?
> > >
> > > A POC for such code btw, can be as follows:
> > >
> > > Pascal:
> > > ...
> > > while not EOF(f) do
> > >   begin
> > >       readln(f,s);
> > >       fpwrite(f2, S[0], length(S));
> > >   end;
> > > ....
> > >
> > > C:
> > > ...
> > > while (! feof(f)) {
> > >   s_size = fread(f, s, MAX_BUFFER);
> > >   write(f2, s, s_size);
> > > }
> > > ...
> >
> > What error do you get? Lastly I had something similar with fpc writing
> > to fast to a non-blocking stderr channel. I haven't had time to do for
> > my code, but if you get "ressource temporartily unavailable"-like errors
> > switching the file to blocking mode might help.
> >
> > Something like
> >
> >         fcntl(fileno(stderr), F_GETFL) & O_NONBLOCK
> >
> > or the pascal equivalent should do.
> 
> I'm getting -1 from fpWrite for a "long" period of time, like 6-7 loop
> returns before it can continue getting the my next content, only to
> have the same problem repeated...

Have you tried getting the os error?

GetLastOSError() from sysutils is your friend, otherwise gdb does a good
job in catching exceptions early and backtracing.

Marc





More information about the fpc-pascal mailing list