Article View: comp.lang.pascal.borland
Article #421Multiple file open/close anomaly?
From: Robert AH Prins
Date: Fri, 04 Dec 1998 00:00
Date: Fri, 04 Dec 1998 00:00
50 lines
2198 bytes
2198 bytes
Take this snippet:
const
sfile: integer = -1;
procedure open(_file: integer);
begin
{$ifdef fast}
if _file <> sfile then
begin;
sfile:= _file;
{$endif}
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}
It's used a program in which many procedures can write their results to one
of two files (a per event file and a summary file). Going through the
program, I suddenly realized that I had never tracked calls to "open", and
much to my surprise I discovered that on several occasions it's called with
the same value for _file on several consecutive invovations. So I added the
conditionals, and timed again, clean DOS, SMARTDRV with write caching, and
running both the old and the new versions several times in alternating
succession. Much to my surprise the old version, which performs the code
dozens of times more than the the new version, is actually faster! (NB: The
file is initially opened for summary data in the main program)
Does anyone have an explanation?
Thanks,
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:
<749jnl$slc$1@nnrp1.dejanews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111659,df5b94058f04a442,start X-Google-Attributes: gid111659,public X-Google-Thread: 108ebd,df5b94058f04a442,start X-Google-Attributes: gid108ebd,public From: Robert AH Prins <prinsra@williscorroon.com> Subject: Multiple file open/close anomaly? Date: 1998/12/04 Message-ID: <749jnl$slc$1@nnrp1.dejanews.com> X-Deja-AN: 418732411 X-Http-Proxy: 1.0 x5.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: Fri Dec 04 21:20:56 1998 GMT Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal X-Http-User-Agent: Mozilla/3.0 (Win16; I)