-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
enhancementSomething can be improvedSomething can be improvedwontfixThis will not be worked onThis will not be worked on
Description
STL/stl/src/filesystem_space.cpp
Lines 19 to 33 in da0d8cf
| static_assert(sizeof(uintmax_t) == sizeof(ULARGE_INTEGER) && alignof(uintmax_t) == alignof(ULARGE_INTEGER), | |
| "Size and alignment must match for reinterpret_cast<PULARGE_INTEGER>"); | |
| [[nodiscard]] __std_win_error _Fs_space_attempt(wchar_t* const _Temp_buffer, const DWORD _Temp_buffer_characters, | |
| const wchar_t* const _Target, uintmax_t* const _Available, uintmax_t* const _Total_bytes, | |
| uintmax_t* const _Free_bytes) noexcept { | |
| if (GetVolumePathNameW(_Target, _Temp_buffer, _Temp_buffer_characters)) { | |
| if (GetDiskFreeSpaceExW(_Temp_buffer, reinterpret_cast<PULARGE_INTEGER>(_Available), | |
| reinterpret_cast<PULARGE_INTEGER>(_Total_bytes), reinterpret_cast<PULARGE_INTEGER>(_Free_bytes))) { | |
| return __std_win_error::_Success; | |
| } | |
| } | |
| return __std_win_error{GetLastError()}; | |
| } |
In #356 (comment), @sylveon asked whether this static_assert and reinterpret_cast technique is necessary. I believe that we could avoid this by defining ULARGE_INTEGER local variables, passing their addresses to GetDiskFreeSpaceExW(), and then if successful, writing their QuadParts to _Available, _Total_bytes, and _Free_bytes. This would involve a few more instructions, but I don't believe that the code size and runtime impact would be observable, and avoiding reinterpret_cast may be worth it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementSomething can be improvedSomething can be improvedwontfixThis will not be worked onThis will not be worked on