public static List <ProcessorInfo> GetProcessorInfo64() { uint iReturnLength = 0; SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64[] oDummy = null; bool bResult = GetLogicalProcessorInformation(oDummy, ref iReturnLength); if (bResult) { throw Fail("GetLogicalProcessorInformation failed.", "x64"); } int iError = Marshal.GetLastWin32Error(); if (iError != ERROR_INSUFFICIENT_BUFFER) { throw Fail("Insufficient space in the buffer.", "x64", iError.ToString()); } uint iBaseSize = (uint)Marshal.SizeOf(typeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64)); uint iNumberOfElements = iReturnLength / iBaseSize; SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64[] oData = new SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64[iNumberOfElements]; uint iAllocatedSize = iNumberOfElements * iBaseSize; if (!GetLogicalProcessorInformation(oData, ref iAllocatedSize)) { throw Fail("GetLogicalProcessorInformation failed", "x64", Marshal.GetLastWin32Error().ToString()); } // Converting the data to a list that we can easily interpret. List <ProcessorInfo> oList = new List <ProcessorInfo>(); foreach (SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64 oInfo in oData) { oList.Add(new ProcessorInfo(oInfo.Relationship, oInfo.Flags, oInfo.ProcessorMask)); } return(oList); }
private static List<ProcessorInfo> GetProcessorInfo64() { //---------------------------------------------- // Intel Corporation // Copyright © 2009/2010 - All Rights Reserved // Department : SST/NTE // Written by : Bill Hines - [email protected] // Modified by : N/A // Date : 12/4/2009 //---------------------------------------------- // First we're going to execute GetLogicalProcessorInformation // once to make sure that we determine the size of the data // that it is going to return. // This call should fail with error ERROR_INSUFFICIENT_BUFFER. //---------------------------------------------- uint iReturnLength = 0; SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64[] oDummy = null; bool bResult = GetLogicalProcessorInformation(oDummy, ref iReturnLength); if (bResult) { throw Fail("GetLogicalProcessorInformation failed.", "x64"); } //---------------------------------------------- // Making sure that the error code that we got back is not // that there is in sufficient space in the buffer. //---------------------------------------------- int iError = Marshal.GetLastWin32Error(); if (iError != ERROR_INSUFFICIENT_BUFFER) { throw Fail( "Insufficient space in the buffer.", "x64", iError.ToString()); } //---------------------------------------------- // Now that we know how much space we should reserve, // we're going to reserve it and call // GetLogicalProcessorInformation again. //---------------------------------------------- uint iBaseSize = (uint)Marshal.SizeOf( typeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64)); uint iNumberOfElements = iReturnLength / iBaseSize; SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64[] oData = new SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64[iNumberOfElements]; uint iAllocatedSize = iNumberOfElements * iBaseSize; if (!GetLogicalProcessorInformation(oData, ref iAllocatedSize)) { throw Fail("GetLogicalProcessorInformation failed", "x64", Marshal.GetLastWin32Error().ToString()); } //---------------------------------------------- // Convert data to a list that can be interpreted. //---------------------------------------------- List<ProcessorInfo> oList = new List<ProcessorInfo>(); foreach (SYSTEM_LOGICAL_PROCESSOR_INFORMATIONx64 oInfo in oData) { oList.Add(new ProcessorInfo( oInfo.Relationship, oInfo.Flags, oInfo.ProcessorMask)); } return oList; }