Experimental reimplementations of some Windows API functions taking std::wstring_view as argument
Modern C++ and other languages today provide extensive facilities to efficiently work with strings, especially with substrings, that aren't NUL-terminated. But a vast majority of Windows API function calls, e.g. CreateFile, consume their string argument(s) via NUL-terminated strings. This forces the application to allocate an unnecessary NUL-terminated copy of the string.
Those Win32 API functions then convert these parameters into UNICODE_STRINGs before passing it to appropiate NT API(s). UNICODE_STRING is basically a potentially-owning limited-size wstring_view.
This effectively means Windows is vasting millions of cycles a second by doing allocations and copying that's unnecessary.
If Windows were to implement parallel set of Win32 APIs to support std::wstring_view
, what could they look like?
Note: Microsoft would probably use two parameters, LPWCSTR
and SIZE_T
, but we can afford actual std::wstring_view
for our experiments.
- RtlInitUnicodeString level:
https://github.com/tringi/papers/blob/main/win32-wstring_view_api.md
- alternatively the application could detour the
RtlInitUnicodeString
for itself
- alternatively the application could detour the
-
(S/G)etThreadDescriptionV alternative to (S/G)etThreadDescription
-
CreateFileV alternative to CreateFileW
- currently only partially implemented