How can I avoid file fragmentation when writing hundreds of files with several megabytes?

My question is similar to How to avoid hard disk fragmentation? , but I will generate several hundred files per day, the size of which can vary from 2 MB to 100 + MB (this questionnaire implied that his files were smaller, since he was more worried about cluttering the disk, my problem is the read performance of these files) . These files are written a little at a time (registration data), which is the best way to create fragmentation. (Database is not an option.) I have code to defragment after they are completely written, but performance suffers for reading files on the same day.

It seems like a way to do this is suggested. How to limit file fragmentation when working with .NET? ; they are inaccurate (and I am in C ++). I would use SetFilePointerEx () and SetEndOfFile () to start working with the file up to 2 MB, and then when the file reaches the selected size, I resized based on the observed growth rate. Then, when recording is complete, resize to the actual size of the data.

One error that I see (actually http://www.cplusplus.com/forum/windows/22114/ pointed to this) that will happen if my application crashes or the computer shuts down. Now I have undefined data in my file and I can not detect it through Windows. This suggests that I am creating a file to track how much data has been written, both to the file and to one file. Is there a better strategy? Perhaps writing enough zeros after each record to later detect (and then back up to be ready for the next record)?

Do you see any other errors that I missed?

+3
source share
1 answer

preallocation 500 . , , , , ( ) .

, , , , , 2 ?

+2

All Articles