Beispiel #1
0
        private static List <ProcessorInfo> GetProcessorInfo86()
        {
            // 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;

            SystemLogicalProcessorInformatioNx86[] oDummy = null;
            bool bResult = GetLogicalProcessorInformation(oDummy,
                                                          ref iReturnLength);

            if (bResult)
            {
                throw Fail("GetLogicalProcessorInformation failed.", "x86");
            }

            // Making sure that the error code that we got back isn't that
            // there is insufficient space in the buffer.
            int iError = Marshal.GetLastWin32Error();

            if (iError != ErrorInsufficientBuffer)
            {
                throw Fail(
                          "Insufficient space in the buffer.",
                          "x86", iError.ToString(CultureInfo.InvariantCulture));
            }

            // Now that we know how much space we should reserve,
            // we're going to reserve it and call
            // GetLogicalProcessorInformation again.
            var iBaseSize = (uint)Marshal.SizeOf(
                typeof(SystemLogicalProcessorInformatioNx86));
            uint iNumberOfElements = iReturnLength / iBaseSize;
            var  oData             =
                new SystemLogicalProcessorInformatioNx86[iNumberOfElements];
            uint iAllocatedSize = iNumberOfElements * iBaseSize;

            if (!GetLogicalProcessorInformation(oData, ref iAllocatedSize))
            {
                throw Fail(
                          "GetLogicalProcessorInformation failed",
                          "x86",
                          Marshal.GetLastWin32Error().ToString(CultureInfo.InvariantCulture));
            }

            // Converting the data to a list that we can easily interpret.
            return(oData.Select(oInfo => new ProcessorInfo(oInfo.Relationship, oInfo.Flags, oInfo.ProcessorMask)).ToList());
        }
Beispiel #2
0
        private static List<ProcessorInfo> GetProcessorInfo86()
        {
            // 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;
            SystemLogicalProcessorInformatioNx86[] oDummy = null;
            bool bResult = GetLogicalProcessorInformation(oDummy,
                                                          ref iReturnLength);
            if (bResult)
            {
                throw Fail("GetLogicalProcessorInformation failed.", "x86");
            }

            // Making sure that the error code that we got back isn't that 
            // there is insufficient space in the buffer.
            int iError = Marshal.GetLastWin32Error();
            if (iError != ErrorInsufficientBuffer)
            {
                throw Fail(
                    "Insufficient space in the buffer.",
                    "x86", 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(SystemLogicalProcessorInformatioNx86));
            uint iNumberOfElements = iReturnLength / iBaseSize;
            SystemLogicalProcessorInformatioNx86[] oData =
                new SystemLogicalProcessorInformatioNx86[iNumberOfElements];
            uint iAllocatedSize = iNumberOfElements * iBaseSize;
            if (!GetLogicalProcessorInformation(oData, ref iAllocatedSize))
            {
                throw Fail(
                    "GetLogicalProcessorInformation failed",
                    "x86",
                    Marshal.GetLastWin32Error().ToString());
            }

            // Converting the data to a list that we can easily interpret.
            List<ProcessorInfo> oList = new List<ProcessorInfo>();
            foreach (SystemLogicalProcessorInformatioNx86 oInfo in oData)
            {
                oList.Add(new ProcessorInfo(oInfo.Relationship,
                                            oInfo.Flags,
                                            oInfo.ProcessorMask));
            }
            return oList;
        }