Reputation: 278
My program is writing large numbers (250,000 at a time) of uint16_t's to a file. For some reason, setting the ios::out flag (unnecessary, since VS2010 sets it automatically) results in a performance decrease of roughly 10x. (see before/after). Any idea what it is about setting that flag that could cause such a huge performance difference?
Before:
fileoutput.flags(ios::out);
After:
//fileoutput.flags(ios::out);
Upvotes: 3
Views: 467
Reputation: 6914
flags
should be used to set format flags of the stream, for example whether output is left or right aligned or boolean values should printed as number or string, so you can't use it to set open mode of the stream and actually calling fileoutput.flags(std::ios::out)
is a call with an invalid argument. and possible reason of the error is in your implementation value of std::ios::out
is equal to std::ios::unitbuf
that cause flush of buffer for each single insertion that certainly cause a huge performance penalty.
Upvotes: 5
Reputation: 709
flags functions doesn't set one flag. It changes all the flags at once. To modify one flag you should use setf/unsetf.
Upvotes: 3