In a recent reply here, I posted some code that used fwrite() to write
binary data to a file. One version of this code used mmap() to access
this binary data in-situ, and I wonder if I should have called fflush() before calling mmap().
I understand the where to use fflush() on standard text formatted output (where you use fprintf(), etc to externalize the output), but I don't see anything my copies of either the ISO C or POSIX standards that say that
I /should/ use fflush(), but neither do I see anything that says I /need
not/ use fflush().
So, wiser and more experienced minds, should I use fflush() in this case
or not?
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
In a recent reply here, I posted some code that used fwrite() to write
binary data to a file. One version of this code used mmap() to access
this binary data in-situ, and I wonder if I should have called fflush()
before calling mmap().
I understand the where to use fflush() on standard text formatted output
(where you use fprintf(), etc to externalize the output), but I don't see
anything my copies of either the ISO C or POSIX standards that say that
I /should/ use fflush(), but neither do I see anything that says I /need
not/ use fflush().
So, wiser and more experienced minds, should I use fflush() in this case
or not?
Yes, do use fflush().
In the alternative, do a setbuf( file, 0 ) so that 'file' is
unbuffered.
In a recent reply here, I posted some code that used fwrite() to write
binary data to a file. One version of this code used mmap() to access
this binary data in-situ, and I wonder if I should have called fflush() before calling mmap().
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 151:46:54 |
Calls: | 10,383 |
Files: | 14,054 |
Messages: | 6,417,815 |