MetallicPriest
MetallicPriest

Reputation: 30825

Defering FILE flush to when the file is closed

I want to defer flushing the contents of the FILE* to when fclose is called. In other words, I only want to write to disk when fclose is called and keep buffering the contents until then. Is it possible to do that with FILE* or I need to write my own code?

Upvotes: 3

Views: 99

Answers (1)

Moo-Juice
Moo-Juice

Reputation: 38820

If you want to buffer (and under no circumstances write to the disk until the file is closed), then your best bet is to write to a buffer in memory (assuming that it will fit in memory, of course), and then write that buffer in one go and then call fclose().

Upvotes: 10

Related Questions