delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/10/22/05:30:07

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Trace-PostClient-IP: 68.147.131.211
From: Brian Inglis <Brian DOT Inglis AT SystematicSW DOT Invalid>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: fstream and fflush
Organization: Systematic Software
Message-ID: <c5jhn011q2617u650ginng48u9dnrd5b3j@4ax.com>
References: <cl92jr$3ro$1 AT coranto DOT ucs DOT mun DOT ca> <cl96k3$45r$1 AT coranto DOT ucs DOT mun DOT ca>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Lines: 34
Date: Fri, 22 Oct 2004 09:20:33 GMT
NNTP-Posting-Host: 24.71.223.147
X-Complaints-To: abuse AT shaw DOT ca
X-Trace: pd7tw1no 1098436833 24.71.223.147 (Fri, 22 Oct 2004 03:20:33 MDT)
NNTP-Posting-Date: Fri, 22 Oct 2004 03:20:33 MDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Thu, 21 Oct 2004 18:06:19 -0230 in comp.os.msdos.djgpp, Jason Mills
<jmills AT cs DOT mun DOT ca> wrote:

>Jason Mills wrote:
>> After a few hours or debugging, I reached the conclusion
>> that to flush a C++ fstream, you must either fstream::close(),
>> or call fflush(NULL). Is this normal? Or is it a bug?
>
>Actually, the above is not correct. Sorry.
>
>After more tests, I discovered that fstream::flush() and fflush(NULL)
>both will not flush the stream if I am writing rapidly to the stream.
>If I sleep(), (maybe if I a do other work, I have not checked)
>the stream is eventually flushed. Can someone explain?

How are you testing this? From another window, or another system on a
network? 
The flush() operations just write the program's buffer(s) to the DOS
file buffer(s), it doesn't write the DOS file buffer(s) to the file
system disk cache, nor flush the file system disk cache to the disk
immediately. You need to call fsync(), and/or sync(), and/or
_flush_disk_cache(), to do the rest. 

Even then I'm not sure that Windows makes cache updates visible
immediately (like Unix) to other processes or systems on a network
before the cache is flushed to disk and/or the file is closed,
depending on when it updates the clusters in the FAT or blocks used in
the FS. 

-- 
Thanks. Take care, Brian Inglis 	Calgary, Alberta, Canada

Brian DOT Inglis AT CSi DOT com 	(Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
    fake address		use address above to reply

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019