4 ms·
> Microsoft could fix this problem by using something other than a monotonically increasing log-file number. If they used the current date and time (to millisec
by gwern 8y ago
> Microsoft could fix this problem by using something other than a monotonically increasing log-file number. If they used the current date and time (to millisecond or higher resolution) as part of the file name then they would get log file names that were more semantically meaningful, and could be created extremely quickly with virtually no unique-file-search logic.
Does Windows have no equivalent of `mktemp`? Getting unique identifiers is a common requirement.
- LeifCarrotson 8y agoIt does, but it puts them in the %appdata%/Temp folder. Which can be deleted by disk space cleanup. I don't think there's a built-in to get unique names in arbitrary folders, other than the idiomatic timestamp method described.
- brucedawson 8y agoWell, arguably putting the log files in the temp folder so that they get cleaned up would be an improvement - currently the log files are never cleared without user action, and most developers don't even know the log files are created. I suspect that the other reason to not use some mktemp equivalent is that they wanted the names to have some logical order to them, it just turns out that ascending file numbers is a bad way to do this.
- electroly 8y agoYou have it backwards. GetTempFileName() only gives you unique names in arbitrary folders! If you want to use %APPDATA%\Temp, you have to call GetTempPath() yourself and pass that path into GetTempFileName().
- TimJYoung 8y agoYes: https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-gettempfilenamea https://docs.microsoft.com/en-us/windows/desktop/api/fileapi...