Skip to content

writer_base::flush_to_file should always clear buffers#240

Merged
kennykerr merged 3 commits into
microsoft:masterfrom
oldnewthing:always-clear
Mar 22, 2019
Merged

writer_base::flush_to_file should always clear buffers#240
kennykerr merged 3 commits into
microsoft:masterfrom
oldnewthing:always-clear

Conversation

@oldnewthing

Copy link
Copy Markdown
Member

Existing behavior clears buffers only if the existing file is different from the buffer contents. Should clear
unconditionally to permit deterministic behavior.

Test:

struct writer : xlang::text::writer_base<writer> { } w;
w.write("hi");
w.flush_to_file(std::string("one"));
w.flush_to_file(std::string("two"));

Run this program twice.

Old behavior: The first time you run it, "one" contains "hi" and "two" is empty. The second time you run it, "one" contains 'hi" and "two" also contains "hi". Contents of file "two" depends on factors not under app's control.

New behavior: Regardless of status of existing files "one" and "two", "one" always contains "hi" and "two" is always empty.

Existing behavior clears buffers only if the existing file
is different from the buffer contents. Should clear
unconditionally to permit deterministic behavior.

Test:
    struct writer : xlang::text::writer_base<writer> { } w;
    w.write("hi");
    w.flush_to_file("one");
    w.flush_to_file("two");

Run this program twice.

Old behavior: The first time you run it, "one" contains "hi"
and "two" is empty. The second time you run it, "one"
contains 'hi" and "two" also contains "hi". Contents of
file "two" depends on factors not under app's control.

New behavior: Regardless of status of existing files "one"
and "two", "one" always contains "hi" and "two" is always
empty.
@kennykerr kennykerr merged commit 5ad5869 into microsoft:master Mar 22, 2019
@oldnewthing oldnewthing deleted the always-clear branch March 25, 2019 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants