Article View: comp.lang.pascal.borland
Article #420Re: Multiple file open/close anomaly?
From: Pedt Scragg
Date: Mon, 07 Dec 1998 00:00
Date: Mon, 07 Dec 1998 00:00
74 lines
3100 bytes
3100 bytes
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.
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}
> 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.
--
Pedt
In principle, is there uncertainty that
Heisenberg was working his best in chaos?
Technical Details
Message-ID:
<J5r+FNAGY7a2Yw7Y@pedt.demon.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<749jnl$slc$1@nnrp1.dejanews.com> <iIck5MAYzqa2YwMz@pedt.demon.co.uk> <74g8pv$59r$1@nnrp1.dejanews.com>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: Pedt Scragg <newsmaster@pedt.demon.co.uk> Subject: Re: Multiple file open/close anomaly? Date: 1998/12/07 Message-ID: <J5r+FNAGY7a2Yw7Y@pedt.demon.co.uk> X-Deja-AN: 419593035 X-NNTP-Posting-Host: pedt.demon.co.uk:194.222.191.220 References: <749jnl$slc$1@nnrp1.dejanews.com> <iIck5MAYzqa2YwMz@pedt.demon.co.uk> <74g8pv$59r$1@nnrp1.dejanews.com> X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 913030016 nnrp-02:10995 NO-IDENT pedt.demon.co.uk:194.222.191.220 Organization: Ty Llyffant Web MIME-Version: 1.0 Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal