🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.borland
Article #412

Re: Multiple file open/close anomaly?

#412
From: Robert AH Prins
Date: Mon, 07 Dec 1998 00:00
110 lines
4534 bytes
In article <J5r+FNAGY7a2Yw7Y@pedt.demon.co.uk>,
  Pedt Scragg <newsmaster@pedt.demon.co.uk> wrote:
> Robert AH Prins [mailto:prinsra@williscorroon.com] decided it was an
> auspicious moment for:
>
> <opening and closing file if needed>
> >> >
> >> I initially assumed that you were opening the file if actually needed.
> >> However, re-reading your code with the {$ifdef} more carefully, I see
> >> that the extra code is not actually doing anything that affects the
> >> process so the code is probably a bit slower just due to the extra bits
> >> you've added.
> >
> >Yes, but don't you think (that's at least what I did!) that a simple if test
> >should be quite a lot faster than closing a file, and opening another one?
>
> Should definitely be faster. The file opening/closing overhead is
> significant if needed to be called a lot of times in the program.
>
> >{$ifdef fast}
> >  if _file <> sfile then
> >    begin;
> >      sfile:= _file;
> >{$endif}
> >      close(datatout);
> >      assign(datatout, files[_file]);
>
> The problem with your {$ifdef fast}/{$endif} pairs is that they are
> adding the conditional test to the file number but you then run the
> close/assign/open part as well.

No, I don't, as can easily be demonstrated by putting a
"writeln('Close/Open');" in the code between begin & end.

> Leaving the conditionals in but rearranging them and the code slightly
> to use the opposite conditional check (I deleted the conditionals from
> the previous post which in hindsight perhaps I should not have done)
>
> const
>   sfile: integer = -1;
>
> procedure open(_file: integer);
> begin
>
> {$ifdef fast}
>   if _file = sfile then exit else
>     begin
> {$endif}
>       sfile:= _file;
>       close(datatout);
>       assign(datatout, files[_file]);
>       settextbuf(datatout, databuf^, 8192);
>
>       if __first_event then
>         begin
>           rewrite(datatout);
>           __first_event:= false;
>         end
>       else
>         append(datatout);
> {$ifdef fast}
>     end;
> {$endif}
> end; {open}

Your code is doing exactly what my code is doing, be it that we use opposite
test to skip the close/open section...

But if you look at the code generated for the if-statement in the two cases,
you'll see that my code is a trifle shorter:

My code:

cs:05AE 55             push   bp
cs:05AF 89E5           mov    bp,sp
cs:05B1 8B4604         mov    ax,[bp+04]
cs:05B4 3B060A2A       cmp    ax,[2A0A]
cs:05B8 7503           jne    05BD
cs:05BA E98000         jmp    063D
cs:05BD 8B4604         mov    ax,[bp+04]
cs:05C0 A30A2A         mov    [2A0A],ax

Your code:

cs:05AE 55             push   bp
cs:05AF 89E5           mov    bp,sp
cs:05B1 8B4604         mov    ax,[bp+04]
cs:05B4 3B060A2A       cmp    ax,[2A0A]
cs:05B8 7506           jne    05C0
cs:05BA E98300         jmp    0640 -+---> Bit silly...
cs:05BD E98000         jmp    0640 -+
cs:05C0 8B4604         mov    ax,[bp+04]
cs:05C3 A30A2A         mov    [2A0A],ax

> > Conditionals have the advantage that you
> >don't have to change your source every time - the code is in an include file,
> >and not a unit.
> >
> Yes, and it is a great advantage. I keep source handy for V5, V5.5, V6
> and V7 and find it invaluable not only for version changes but for
> switching on and off things like stack and range checks. IMHO, the usage
> of conditionals is very underrated.

Robert
--
Robert AH Prins
prinsra@williscorroon.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
Technical Details
Message-ID: <74hegn$6pc$1@nnrp1.dejanews.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <749jnl$slc$1@nnrp1.dejanews.com> <iIck5MAYzqa2YwMz@pedt.demon.co.uk> <74g8pv$59r$1@nnrp1.dejanews.com> <J5r+FNAGY7a2Yw7Y@pedt.demon.co.uk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111659,df5b94058f04a442
X-Google-Attributes: gid111659,public
X-Google-Thread: 108ebd,df5b94058f04a442
X-Google-Attributes: gid108ebd,public
From: Robert AH Prins <prinsra@williscorroon.com>
Subject: Re: Multiple file open/close anomaly?
Date: 1998/12/07
Message-ID: <74hegn$6pc$1@nnrp1.dejanews.com>
X-Deja-AN: 419735831
References: <749jnl$slc$1@nnrp1.dejanews.com> <iIck5MAYzqa2YwMz@pedt.demon.co.uk> <74g8pv$59r$1@nnrp1.dejanews.com> <J5r+FNAGY7a2Yw7Y@pedt.demon.co.uk>
X-Http-Proxy: 1.0 x10.dejanews.com:80 (Squid/1.1.22) for client 193.130.234.1
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Mon Dec 07 20:40:55 1998 GMT
Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal
X-Http-User-Agent: Mozilla/3.0 (Win16; I)