Be more optimistic when querying on Windows?
As a part of cargo crev I was reviewing this crate in version 1.10.1 . All was good, but I have one idea.
It seems like on Windows this crate calls the GetLogicalProcessorInformation twice. Any reason not to start with a buffer of a fix size (eg. 64 entries)? Maybe this initial buffer could be on stack, so it wouldn't really cost anything. On most machines that would cut the number of calls to just 1.
What you say sounds reasonable. I'm not too familiar with Windows programming, but I noticed the source links to an example on MSDN, and it looks like they also query once to get the size needed. Is the example naive?
Seems so to me. But I have no clue, and haven't wrote for or used Windows in more than a decade, so what do I know. :D
More optimal approach would be to use first call with some stack array of hard-coded size. If function fails with unsufficient memory, then it will update len to required one, in which case you could fallback to heap allocated vec.
This way in happy case the call will be only once.