I use the fwrite() function call to write data to a pipe in Linux.
Previously, fwrite() called for small pieces of data (on average 20 bytes) several times, and buffering remained fwrite() . strace in the process showed that 4096 bytes of data were written each time.
It turned out that this recording process was a bottleneck in my program. So I decided to write the data in my code to 64 KB blocks, and then write the whole block at a time using fwrite() . I used setvbuf() to set the FILE * pointer to "No Buffering".
The performance improvement was not as significant as I expected.
More importantly, strace output showed that the data is still being written 4096 bytes at a time. Can someone please explain this behavior to me? If I call fwrite() with 64 KB of data, why does it only write 4096 bytes at a time?
Is there an alternative to fwrite() to write data to a pipe using the FILE * pointer?
c ++ c linux fwrite
Shailesh tainwala
source share