Suggestion: Preallocated file open - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: Suggestion: Preallocated file open (/showthread.php?tid=1380) Pages:
1
2
|
RE: Suggestion: Preallocated file open - DSMan195276 - 01-09-2023 FWIW such 'preallocate' functionality has benefits beyond just the potential to reduce fragmentation of the underlying file - it's generally an almost instant operation and can be used to ensure there is enough space on the disk to fit your file. If you're writing a 4GB file, it would be much nicer to be able to preallocate the 4GB of space before you do any work and get a quick failure if there is not enough vs. have it fail after you've spent a long time writing that data. The only thing on my mind if we did add such a thing is that I think it would make more sense as a separate PREALLOCATEcommand which takes a file number, rather than another setting on OPENitself. I'm not sure if that would work with how Windows makes you do it though, I'd have to check (on Linux that's fine since fallocate()is a separate function anyway). RE: Suggestion: Preallocated file open - SpriggsySpriggs - 01-10-2023 For the ones who truly need this function (whether because they're dealing with ridiculous text files of inordinate sizes or wanting to save a video), couldn't they also just do a check for available drive space on the destination drive before writing the file in the meantime? Seems like there would be no need to "preallocate" anything if one would just check that they're not trying to fit fifty pounds of flour in a five pound bag. Also, modern Windows automatically schedules defrag tasks for weekly runs. RE: Suggestion: Preallocated file open - DSMan195276 - 01-10-2023 (01-10-2023, 02:45 PM)Spriggsy Wrote: For the ones who truly need this function (whether because they're dealing with ridiculous text files of inordinate sizes or wanting to save a video), couldn't they also just do a check for available drive space on the destination drive before writing the file in the meantime? Seems like there would be no need to "preallocate" anything if one would just check that they're not trying to fit fifty pounds of flour in a five pound bag. Also, modern Windows automatically schedules defrag tasks for weekly runs. You can, but it's not nearly as effective since it doesn't actually guarantee the space will still be there when you get to the end. Say you run two of these processes that make a 4GB file and there's 5GB of disk space left. Both programs will think they have enough, but collectively you will run out before one or both of them can finish creating their files. By preallocating the files one of those processes will fail on the preallocation step instead. RE: Suggestion: Preallocated file open - SpriggsySpriggs - 01-10-2023 In that case, these might be of some help: How do you pre-allocate space for a file in C/C++ on Windows? - Stack Overflow _chsize | Microsoft Learn |