c++ - Improving performance of ofstream? -


i communicating parallel processes using fifos. reading pipe read(). , writing named pipe doing this:

ofstream pipe(namepipe);  pipe << data << endl; pipe.close(); 

i have been noticing performance horrible though! takes 40ms sometimes. it's extreme latency in opinion. read use of std::endl can affect performance. should avoid using endl?

does using ofstream affect performance? there other alternatives method?

thank you!

a cheap hack:

std::ios::sync_with_stdio(false); 

note use if not going mixing c io c++

the reason std::endl might affect i/o performance because flushes stream. avoid this, should use '\n'

avoiding having open , close multiple streams help