Suggestion: Preallocated file open - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/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 `PREALLOCATE` command which takes a file number, rather than another setting on `OPEN` itself. 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 RE: Suggestion: Preallocated file open - SMcNeill - 02-25-2024 (01-10-2023, 09:27 PM)DSMan195276 Wrote:(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. One thing to note here: Preallocation is not the same as Defragmentation. Let's say we have a super large drive that holds 10 elements. We'll represent space on it with 0 for empty, X for full. When we first buy that drive, it's all empty. 0000000000 <-- Looks like this. Now, let's say we write 10 single-space things to that drive. XXXXXXXXXX <-- Now it looks like this. It's all full. So we now want to write some new junk to this drive -- but it's full! To make room, we delete our porn (space 1), hentai (space3), eroge (space 5), and homework folders (space 8). The drive now looks like: 0X0X0XX0XX <-- those spaces we deleted are now empty. Now, if we want to write a 3 space file, we can pre-allocate space for that file -- but it's not going to be defragmented. Instead, it'll look like the following (with P for pre-allocated file space): PXPXPXX0XX Pre-allocation doesn't equate to defragmentation. To keep that file *always* from being defragmented, we'd basically have to first defragment the drive and make it: XXXXXX0000 And then we'd pre-allocate space on that drive for the data: XXXXXXPPP0 ... And depending on the size of that drive, this could make for a VERY long save process for that file! Personally, I think I'd rather just write the file in a fragmented state, and then let the OS defragment itself on its regular maintaince schedule. |