Unbuffered Write / Buffer Flush

Discussion in 'Basic4ppc Wishlist' started by davidmw, Jul 5, 2007.

  1. davidmw

    davidmw Member Licensed User

    I'm working on a data logging feature that will be writing a few bytes at a time to a file. The file will likely be on a removable CF / SD card. The writes will happen every 10 seconds or as slow as every 30 minutes.

    The write buffer associated with the FileWrite command is large enough to hide a significant number of records and a large amount of recording time. Yes if the form is closed or app is terminated the program will close the file and the buffer will be correctly flushed to the file as a result.

    But if a user removes the memory card without first doing something that will cause the file to close - much data will be lost.

    Maybe I should be opening and closing the file for each write. But it would also be nice to have an unbuffered write or flush command available.

    In terms of the expected lifespan of SD and CF memory - doing larger buffered writes might be the best for the memory card. But if that isn't a good option, would lots of small unbuffered writes to the end of an open file cause less wear than opening, appending, and closing the file each time?

    It would seem like the file open / close technique would be causing frequent updates to the FAT or directory and that could result in more than a single file being damaged.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The only way to 100% flush data to a storage card is to close the file stream.
    The OS has an internal cache that can't be flushed otherwise.
     
  3. agraham

    agraham Expert Licensed User

    I wouldn't worry about it - just close the file each time, particularly as you seem to be intending to write with a frequency in the high seconds or low minutes. Some/most devices nowadays employ some form of flash management in their low level drivers to even out wear on the memory.

    Flash is so cheap anyway that if it is a critical application then tell the user to change the memory every six months or so like we used to change lead-acid batteries on float charge backing up critical industrial logging systems.
     
  4. davidmw

    davidmw Member Licensed User

    Erel and agraham,

    Many thanks. My application came together in three days with your great product and support. I'm off to buy Basic4ppc. Then to add charting ...
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    As we are looking for quotes I ask your permission to use this one ;)
     
  6. davidmw

    davidmw Member Licensed User

    Erel,

    Yes that would be fine since it is already on the forum. I may be able to give you more detail and links later but I'd like more experience with the product first.
     
Loading...