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

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Jason Mills <jmills AT cs DOT mun DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: fstream and fflush
Date: Fri, 22 Oct 2004 07:58:06 -0230
Organization: Memorial University of Newfoundland
Lines: 36
Message-ID: <clanbn$8j1$1@coranto.ucs.mun.ca>
References: <cl92jr$3ro$1 AT coranto DOT ucs DOT mun DOT ca> <cl96k3$45r$1 AT coranto DOT ucs DOT mun DOT ca> <2tqpgmF245sdvU4 AT uni-berlin DOT de>
NNTP-Posting-Host: jmills.ccore.mun.ca
Mime-Version: 1.0
X-Trace: coranto.ucs.mun.ca 1098440887 8801 134.153.38.195 (22 Oct 2004 10:28:07 GMT)
X-Complaints-To: usenet AT coranto DOT ucs DOT mun DOT ca
NNTP-Posting-Date: Fri, 22 Oct 2004 10:28:07 +0000 (UTC)
User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)
X-Accept-Language: en-us, en
In-Reply-To: <2tqpgmF245sdvU4@uni-berlin.de>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Hans-Bernhard Broeker wrote:

> Jason Mills <jmills AT cs DOT mun DOT ca> wrote:
> 
> 
>>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?
> 
> 
> What exactly do you expect flush() to do for you,  if you keep writing
> stuff to the file afterward

Two things:
1. It is a log file, so I wanted to make sure a log record is written
to the disk as soon as possible so no records are lost, on a crash
for example.
2. Perhaps unwisely, I was using stat() to query the file size
periodically in order to rotate the log file based on file size. (I
have since changed this design.)

 >
 > i.e. how do you define that it did "not
 > flush the stream"?
 >

For example, I had the logger configured to create 1M log files. But
because flush did not dump any records to the file, stat() always
reported a file size of 0M. Hence (e.g.) my log file reached a size
of 19M when I finally killed the program.

When I killed the program, the data was written. But will this happen
if the power to the machine is cut? If not I lose log records.

Jason

- Raw text -


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