I have a memory heap manager which partitions the heap into different segments based on the number of processors on the system. Memory can only be allocated on the partitio
In addition to Antony Vennard's answer and the code on the cited site, here is code that will work for Visual C++ x64 as well (no inline assembler):
DWORD GetCurrentProcessorNumberXP() {
int CPUInfo[4];
__cpuid(CPUInfo, 1);
// CPUInfo[1] is EBX, bits 24-31 are APIC ID
if ((CPUInfo[3] & (1 << 9)) == 0) return -1; // no APIC on chip
return (unsigned)CPUInfo[1] >> 24;
}
A short look at the implementation of GetCurrentProcessorNumber() on Win7 x64 shows that they use a different mechanism to get the processor number, but in my (few) tests the results were the same for my home-brewn and the official function.