MFILE removal

1 view
Skip to first unread message

Nicolas Alvarez

unread,
Oct 21, 2009, 6:17:54 PM10/21/09
to synecdo...@googlegroups.com
There are only two things left using MFILE: the GUI RPC client library
(which I intend to completely replace some day), and the client_state.xml
saving code.

All the code that writes XML to make the client_state.xml file was already
converted to iostreams. Only the "top-level" step, creating the file
(write_state_file), is still using a MFILE/MIOFILE. Then that MIOFILE is
wrapped in an ostream when passed to write_state().

write_state_file creates an MFILE because that way all the data is buffered
in memory first, and only written to disk when closed. But I don't see why
this is needed. It's writing to client_state_next.xml, closing, and then
renaming it to client_state.xml. I don't see any potential problem in
writing the _next file "incrementally" instead of first buffering it all.

I attach a proposed patch to make write_state_file use a std::ofstream.
I'd like some pre-commit reviewing...

The diff may be a bit hard to follow. It may be better to apply the patch
locally and review the resulting code instead of looking at the patch.

cs_statefile.C.diff

Der Meister

unread,
Oct 22, 2009, 12:16:58 PM10/22/09
to synecdo...@googlegroups.com
Nicolas Alvarez wrote:
> write_state_file creates an MFILE because that way all the data is buffered
> in memory first, and only written to disk when closed. But I don't see why
> this is needed. It's writing to client_state_next.xml, closing, and then
> renaming it to client_state.xml. I don't see any potential problem in
> writing the _next file "incrementally" instead of first buffering it all.
This might have some implications on the performance, mainly increase
disc-load, if the code writing to the ofstream uses std::endl or
std::flush more than once. As long as this isn't the case it shouldn't
be a problem as std::ofstream and the underlying implementation should
already use some buffering which may even be better then the one
provided by MFILE (regarding to memory usage).

Nicolas Alvarez

unread,
Oct 22, 2009, 12:37:39 PM10/22/09
to synecdo...@googlegroups.com

An ofstream is of course buffered, but that buffer will probably not fit the
entire client_state.xml file.

Synecdoche isn't using std::flush or std::endl anywhere, except when writing
to std::cerr.


David Barnard

unread,
Oct 22, 2009, 12:59:32 PM10/22/09
to synecdo...@googlegroups.com
On Thu, Oct 22, 2009 at 5:37 PM, Nicolas Alvarez
<nicolas...@gmail.com> wrote:
> An ofstream is of course buffered, but that buffer will probably not fit the
> entire client_state.xml file.

I think the size of the buffer can be changed using the filebuf.

Der Meister

unread,
Oct 22, 2009, 2:40:08 PM10/22/09
to synecdo...@googlegroups.com
I don't think that adjusting the buffer size is necessary but using
std::endl or std::flush would flush the buffer and doing so after
(almost) each line would be really terrible. That's why I've asked.
Reply all
Reply to author
Forward
0 new messages