We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I'm using the file system (MDK File System Component, MDK 7.17.3) to log data to an SD-Card. The amount of data may vary from hundrets of lines per second to a single line every few seconds. To my understanding data is bufferd within the standard library and the file system before it is written to non volatile memory. My assumption is that data is only written to non volatile memory once buffers run full (is this correct?). When the data rate is small (a line every few seconds) it might take a while until data is written to non volatile memory. To put an upper limit to the amount data that would be lost if the device loses power I'm frequently (e.g. each minute) closing and reopening the file using fclose/fopen. I've noticed that fopen might take quiet long (a few seconds) if there are many files (50+) on the SD-Card (File name cache is disabled, due to memory constraints).
My question is whether there is a more efficient way to flush the file system buffers to disk. Unix systems have the fsync function that does exactly that. The closest MDK function that I've found is fflush, but the documentation says that for FAT file systems this only flushes internal buffers but doesn't write data to disk. Is freopen more efficent than explicitly calling fclose/fopen?
Best,
Valentin