Created
November 13, 2021 00:03
-
-
Save khchen/12a095be93faca927af5bd06d6750932 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[ | |
| Author: Ward | |
| Example of GetLogicalProcessorInformation | |
| References: | |
| https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getlogicalprocessorinformation | |
| ]# | |
| import winim/lean | |
| var returnedLength: DWORD | |
| GetLogicalProcessorInformation(nil, &returnedLength) | |
| let count = returnedLength div sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) | |
| # Use newSeq | |
| block: | |
| var buffer = newSeq[SYSTEM_LOGICAL_PROCESSOR_INFORMATION](count) | |
| GetLogicalProcessorInformation(&buffer[0], &returnedLength) | |
| for i in buffer: | |
| echo i | |
| # Use alloc | |
| block: | |
| var buffer = cast[ptr SYSTEM_LOGICAL_PROCESSOR_INFORMATION](alloc(returnedLength)) | |
| defer: dealloc(buffer) | |
| GetLogicalProcessorInformation(buffer, &returnedLength) | |
| let arr = cast[ptr UncheckedArray[SYSTEM_LOGICAL_PROCESSOR_INFORMATION]](buffer) | |
| for i in 0 ..< count: | |
| echo arr[i] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment