Skip to content

Instantly share code, notes, and snippets.

@khchen
Created November 13, 2021 00:03
Show Gist options
  • Select an option

  • Save khchen/12a095be93faca927af5bd06d6750932 to your computer and use it in GitHub Desktop.

Select an option

Save khchen/12a095be93faca927af5bd06d6750932 to your computer and use it in GitHub Desktop.
#[
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