non-blocking print to file

I'm writing a logging program, and I need to read from serial once a second then print to a log file. the problem is fprintf and the "<<" operator both block my code while the HDD is accessed and this holds up my loop and the next time i read from serial my time stamp is in accurate. I'm trying to avoid multi threading.

is there a way to do a non-blocking write to file. Basically I want to hand off my string to the OS and and not wait till its done

thanx
Yes, look up overlapped I/O. However, under normal circumstances, writing a small portion of data to a file should return almost immediately and the data will be written to the disk in the background after a few seconds.
You're thinking about this the wrong way, though. If the write operation takes more than "virtually no time", you just need to adjust the time you sleep until you read the next time stamp, so that a total of one second will have passed at the end.
I have created variables to time each line of code in my loop using clock()... but your post forced me to look at my code again, and i realized that I was opening the file everytime and I believed thats what is taking up the time
Topic archived. No new replies allowed.