On Fri Jan 19 04:03:17 2024 +0000, Zhiyi Zhang wrote:
D3DKMT_ENUMADAPTERS2 already has an array for this. I think you can avoid this memory allocation.
Indeed, but I thought it would be safer to allocate some memory for a temporary working area, try enumerating adapters and only copy the result if the entire operation did not fail halfway through rather than using the array I was passed by the caller directly and risk writing some partially misleading garbage to it. I also wasn't sure how to proceed in such case: if I already wrote some LUIDs and handles, should I try to `memset(0)` them just in case or leave the data there and trust that all callers of this API will ignore whatever was written, treating the content as unspecified?
It's also somewhat tricky to cause Windows to fail here so I don't know how exactly does it behave when it encounters some error internally. Copying the full result only on full success seemed like an easy way out that allowed me to not bother figuring this out, even if it costs an extra allocation.
But I can revert to writing to `pAdapters` directly if you'd prefer it that way.