No announcement yet.

Flushing file buffer

  • Filter
  • Time
  • Show
Clear All
new posts

  • Shawn Tartaglia
    Guest replied
    Denny -

    Unless I am missing something, couldn't you also loose the file during the temp file write?

    The only way I can see this helping is if the temp file is much smaller than the final file. Then you would have less of a chance that the temp file gets corrupted.

    Either way I don't think there is actually anything that can be done about this, other than a smart UPS.



    Leave a comment:

  • Denny Moore
    Guest replied
    If you are worried about power failures, etc. when writing to a
    file, you are much better off implementing a "bullet proof"
    method of writing/updating files. I also have such an
    application. Here's how I handle the writing/updating of a file:

    I have a "restart" file that is read by the program when it
    first starts. If any write was interrupted, it will contain an
    integer number to tell me what and where the program was

    When writing a file…
    open a TEMPORARY file, write your updated data.
    close temp file

    open "O",#fn,"Restart.Fil"
    write #fn,whichRestart
    (whichRestart is unique to each file write operation)
    close #fn

    ---Restart point is here <---------------
    copy temp file to real data file

    open "O",#fn,"Restart.Fil"
    write #fn,0 (write a zero to restart file)
    close #fn

    Now, at startup, I open the restart file. If it's zero, continue on normally.
    If it's not zero, go the restart point and finish copying the
    temp file to the final location.

    I make sure each write operation is in a separate subroutine. When called, one of the parameters is the restart value (flag).
    If not zero, the sub bypasses the creation of a temp file and
    does the final file copy.

    My application actually consists of an .exe plus many chain
    modules (.pbc's). I pass the restart code to the appropriate
    pbc via common. The pbc then calls the correct sub using the
    restart code.

    Hope this helps, Denny Moore


    Leave a comment:

  • Matthew Berg
    There is also the RESET command, but it flushes the disc buffers and closes all open files.

    Leave a comment:

  • Phil Kapusta
    Guest replied
    Version 2.1 does not support FLUSH.

    I also do not know assembler or DOS interupts.

    I will therefore have to use the CLOSE/APPEND solution after each PRINT # statement.



    Leave a comment:

  • Michael Mattias
    I can't recall if PB 2.1 lets you use the FLUSH verb, but if not, you can use DOS interrupt x'21' service x'68' once you get the OS handle using FILEATTR (does that work in 2.1?)

    If these don't work, your only other move is to close and reopen the file for APPEND after each critical write.


    Leave a comment:

  • Phil Kapusta
    Guest started a topic Flushing file buffer

    Flushing file buffer

    I am using PowerBasic 2.1f

    How do I flush the file buffer of an open file in order to prevent data loss should the user encounter a lock-up or power loss?


    Open "A", #1, "VITAL.TXT"
    Print #1, "We cannot afford to lose this data"
    ' The power goes out at this point and we end up losing the previous line of data
    Close #1