comp.lang.ada
 help / color / mirror / Atom feed
* Smart to put "Flush(myfile)" before "Close(myfile") ?
@ 2021-01-25  5:42 reinert
  2021-01-25 11:41 ` Jeffrey R. Carter
  2021-01-25 12:05 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 6+ messages in thread
From: reinert @ 2021-01-25  5:42 UTC (permalink / raw)


Can an exception (runtime error) in principle, after closing a file, interrupt the process of writing the actual file to disc?

I.e. is it smart to include a "Flush(myfile)" before "Close(myfile)" like this:

Create  (myfile, Out_File, "myfilename");
... Put .. Put
Flush(myfile);
Close(myfile);

reinert

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Smart to put "Flush(myfile)" before "Close(myfile") ?
  2021-01-25  5:42 Smart to put "Flush(myfile)" before "Close(myfile") ? reinert
@ 2021-01-25 11:41 ` Jeffrey R. Carter
  2021-01-25 12:05 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 6+ messages in thread
From: Jeffrey R. Carter @ 2021-01-25 11:41 UTC (permalink / raw)


On 1/25/21 6:42 AM, reinert wrote:
> Can an exception (runtime error) in principle, after closing a file, interrupt the process of writing the actual file to disc?
> 
> I.e. is it smart to include a "Flush(myfile)" before "Close(myfile)" like this:

In over 35 years of using Ada, I have never done this, and have never had a 
problem. YMMV

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Smart to put "Flush(myfile)" before "Close(myfile") ?
  2021-01-25  5:42 Smart to put "Flush(myfile)" before "Close(myfile") ? reinert
  2021-01-25 11:41 ` Jeffrey R. Carter
@ 2021-01-25 12:05 ` Dmitry A. Kazakov
  2021-01-25 13:32   ` G.B.
  1 sibling, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2021-01-25 12:05 UTC (permalink / raw)


On 2021-01-25 06:42, reinert wrote:
> Can an exception (runtime error) in principle, after closing a file, interrupt the process of writing the actual file to disc?

Depends on the error. If you crash the OS some cached stuff might get 
lost. That depends on the filesystem. If you managed to wipe out the 
RAID controller's cache as well as its persistent memory that would 
destroy anything there. Let your fantasy fly...

> I.e. is it smart to include a "Flush(myfile)" before "Close(myfile)" like this:
> 
> Create  (myfile, Out_File, "myfilename");
> ... Put .. Put
> Flush(myfile);
> Close(myfile);

AFAIK closing file flushes all file buffers and writes the file size. 
Thus calling Flush should change nothing.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Smart to put "Flush(myfile)" before "Close(myfile") ?
  2021-01-25 12:05 ` Dmitry A. Kazakov
@ 2021-01-25 13:32   ` G.B.
  2021-01-26  5:30     ` reinert
  0 siblings, 1 reply; 6+ messages in thread
From: G.B. @ 2021-01-25 13:32 UTC (permalink / raw)


On 25.01.21 13:05, Dmitry A. Kazakov wrote:
> On 2021-01-25 06:42, reinert wrote:
>> Can an exception (runtime error) in principle, after closing a file, interrupt the process of writing the actual file to disc?
> 
> AFAIK closing file flushes all file buffers and writes the file size. Thus calling Flush should change nothing.

If the file is like standard output, say, then writing to its
physical target---there could be redirections etc.--might need
consideration when timing matters.
Also, on Windows™ I'd check the effects that the OS's buffering scheme
is having on synchronization of file contents and on timing.

I'm not sure whether the LRM reaches far enough for your case when it
mentions "internal buffers" and "external file". The latter, in
particular, seems out of reach when the file is read through means
other than Ada's.

Some older note-to-self I found states:
    -- When an I/O exception occurs, and a read-write loop would be
    -- left, it has helped (somewhat) to Flush the output stream
    -- (and possibly close the file).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Smart to put "Flush(myfile)" before "Close(myfile") ?
  2021-01-25 13:32   ` G.B.
@ 2021-01-26  5:30     ` reinert
  2021-01-26  8:01       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 6+ messages in thread
From: reinert @ 2021-01-26  5:30 UTC (permalink / raw)


OBS, me in a state of confusion: I made the original question since the end part of a file were lost (Flush helped to avoid).
However, I now discovered that the actual file sometimes were not closed :-) Anyway, you triggered me to find the bug :-)

reinert



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Smart to put "Flush(myfile)" before "Close(myfile") ?
  2021-01-26  5:30     ` reinert
@ 2021-01-26  8:01       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry A. Kazakov @ 2021-01-26  8:01 UTC (permalink / raw)


On 2021-01-26 06:30, reinert wrote:
> OBS, me in a state of confusion: I made the original question since the end part of a file were lost (Flush helped to avoid).
> However, I now discovered that the actual file sometimes were not closed :-)

This is what Flush is for. E.g. if you have some trace or log file which 
never gets officially closed. Flush sets the file end.

  Anyway, you triggered me to find the bug :-)

You can wrap File_Type in a controlled type to ensure Close called from 
the Finalize.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-26  8:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25  5:42 Smart to put "Flush(myfile)" before "Close(myfile") ? reinert
2021-01-25 11:41 ` Jeffrey R. Carter
2021-01-25 12:05 ` Dmitry A. Kazakov
2021-01-25 13:32   ` G.B.
2021-01-26  5:30     ` reinert
2021-01-26  8:01       ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox