Windows API Reference

Processor Information

This section describes functions and structures used to retrieve detailed information about the processors installed in the system.

Core Concepts

Understanding processor capabilities is crucial for optimizing application performance and ensuring compatibility. Windows provides a set of APIs that allow applications to query information such as the number of processors, cache sizes, clock speed, and feature sets.

Key Functions

GetSystemInfo

Retrieves information about the current system, including the processor architecture, level, revision, page size, and the number of active processors. This is a foundational function for obtaining basic system details.


BOOL GetSystemInfo(
  LPSYSTEM_INFO lpSystemInfo
);
                

The lpSystemInfo parameter points to a SYSTEM_INFO structure that receives the system information.

GetLogicalProcessorInformation

Retrieves extended system information, including processor affinity masks, cache topology, NUMA node information, and more. This function provides a more granular view compared to GetSystemInfo.


BOOL GetLogicalProcessorInformation(
  PSYSHLOGICALPROCESSORINFORMATION Buffer,
  PDWORD ReturnedLength
);
                

The Buffer parameter is a pointer to an array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures. The ReturnedLength parameter specifies the size of the buffer.

Important Structures

SYSTEM_INFO

This structure contains information about the current computer. It includes details relevant to processors and the system in general.

Member Description
wProcessorArchitecture The architecture of the processor (e.g., x86, x64, ARM).
dwPageSize The size of a page in memory, in bytes.
lpMinimumApplicationAddress A pointer to the lowest memory address accessible to applications and DLLs.
lpMaximumApplicationAddress A pointer to the highest memory address accessible to applications and DLLs.
dwActiveProcessorMask A bitmask representing the set of active logical processors.
dwNumberOfProcessors The number of logical processors available on the current system.
dwProcessorType An obsolete member that indicates the processor type.
dwAllocationGranularity The granularity of allocation, in bytes, that is used by the memory allocation functions.
wProcessorLevel The Intel-compatible processor level.
wProcessorRevision The Intel-compatible processor revision.

SYSTEM_LOGICAL_PROCESSOR_INFORMATION

This structure describes the logical processors in a system. It includes information about processor cores, NUMA nodes, and caches.

Member Description
ProcessorMask A KAFFINITY mask that specifies the processors in the group.
Relationship A LOGICAL_PROCESSOR_RELATIONSHIP enumeration value that specifies the relationship between the processors.
ProcessorCore.Flags A flag indicating whether the processor core is the PC-Portable type.
ProcessorCore.NumSymmetricCores The number of symmetric cores in the group.
Cache.Level The cache level (e.g., L1, L2, L3).
Cache.Associativity The associativity of the cache.
Cache.LineSize The cache line size, in bytes.
Cache.Size The total size of the cache, in bytes.
NumaNode.NodeNumber The NUMA node number.

Example Usage

The following C++ code snippet demonstrates how to use GetSystemInfo to retrieve basic processor information:


#include <windows.h>
#include <iostream>

int main() {
    SYSTEM_INFO sysInfo;
    GetSystemInfo(&sysInfo);

    std::wcout << L"Number of Processors: " << sysInfo.dwNumberOfProcessors << std::endl;
    std::wcout << L"Processor Architecture: " << sysInfo.wProcessorArchitecture << std::endl;
    std::wcout << L"Page Size: " << sysInfo.dwPageSize << L" bytes" << std::endl;

    return 0;
}
                
Note: The processor architecture values (e.g., PROCESSOR_ARCHITECTURE_INTEL, PROCESSOR_ARCHITECTURE_AMD64) are defined in winnt.h.
Important: For modern systems with multiple cores and hyperthreading, dwNumberOfProcessors typically reports the number of logical processors, not physical cores. Use GetLogicalProcessorInformation for more detailed topology.