I have noticed a huge performance hit in one of my projects when logging is enabled for the first time. But when the log file limit is reached and the program starts writing to the beginning of the file again, the logging speed is much faster (about 50% faster). It's normal to set the log file size to hundreds of MBs.
Most download managers allocate dummy file with the required size before starting to download the file. This makes the writing more effecient because the whole chunk is allocated at once.
What is the best way to reserve disk space efficiently, by some fixed size, when my program starts for the first time?
wRAR is correct. Open a new file using your favourite library, then seek to the penultimate byte and write a 0 there. That should allocate all the required disk space.
You can use the SetFileValidData function to extend the logical length of a file without having to write out all that data to disk. However, because it can allow to read disk data to which you may not otherwise have been privileged, it requires the
SE_MANAGE_VOLUME_NAME
privilege to use. Carefully read the Remarks section of the documentation.Also implementation of SetFileValidData depend on fs driver. NTFS support it and FAT only since Win7.
Here's a simple function that will work for files of any size:
If you are using C++ 17, you should do it with
std::filesystem::resize_file
Link