I'm maintaining a single-threaded C++ app that has to write a large binary file from time to time. I'd like to minimize the time spent in { stream(fname); stream.write(largebuf}; }, so hand over the data to the OS (Linux) as fast as possible when writing/closing the stream. I'm not really concerned about when the data is actually written physically to the disk.
This could wery well be an OS tuning question (any pointers are welcome) - I'd just like to know if there's anything I can do within the C++ code to improve turnaround time from the block shown above.
thanks, T.
Is there any particular reason you can not use threads? If you don't care when the data is actually written to the disk you can just use threads so you don't block your main thread while writing that large bin file.
PS: the sample is using C++11 features (threads and lambda functions).