...
File buffering is particularly important when data is written in small chunks to a medium with slow write time or limited endurance. An example is NOR flash, or even NAND flash, where write times are much slower than read times, and the lifetime of device is constrained by limits on the number of times each block can be erased and programmed.
Listing 10-3 Example file buffer usage
L10-3(1) The buffer must be assigned immediately after opening the file. An attempt to set the buffer after read or writing the file will fail.
L10-3(2) While it is not necessary to flush the buffer before closing the file, some applications may want to make sure at certain points that all previously written data is stored on the device before writing more.