Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2007

Tip: Looking for answers? Try searching our database.

how to use GetLogicalProcessorInformation, win32api, under using csharp

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ti - 25 May 2007 09:06 GMT
Hello all,

Does anyone have any idea that how to use
GetLogicalProcessorInformation, win32api, under using csharp?
http://msdn2.microsoft.com/en-us/library/ms683194.aspx

For me, one of the most difficult things is how to define
SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures and how to cast it to
the win32api.

Using
StructLayout(LayoutKind.Explicit)
[FieldOffset(0)]...

I've been trying but it's very difficult for me.

Best Regards,
TI
Miroslav Stampar - 25 May 2007 10:41 GMT
public class ProcessorInfo
{
 private string manufacturer = null;
 private UInt32 clockSpeed;
 private UInt16 family;
 private string version;
 private string processorId = null;

 public static void ConsoleOutput()
 {
  ProcessorInfo info = ProcessorInfo.Get();
  Console.WriteLine("\nProcessor information:");
  Console.WriteLine("----------------------");
  Console.WriteLine("Manufacturer: {0}", info.manufacturer);
  Console.WriteLine("ClockSpeed: {0}", info.clockSpeed);
  Console.WriteLine("Family: {0}", info.family);
  Console.WriteLine("Version: {0}", info.version);
  Console.WriteLine("ProcessorId: {0}", info.processorId);
  Console.WriteLine("\n");
 }

 public static ProcessorInfo Get()
 {
  ProcessorInfo output = new ProcessorInfo();
  ManagementObjectSearcher searcher = new
ManagementObjectSearcher("SELECT * FROM Win32_Processor");
  foreach (ManagementObject wmi_CPU in searcher.Get())
  {
   output.manufacturer = wmi_CPU["Manufacturer"].ToString();
   output.clockSpeed = (UInt32) wmi_CPU["MaxClockSpeed"];
   output.family = (UInt16) wmi_CPU["Family"];
   output.version = wmi_CPU["Version"].ToString();
   output.processorId = wmi_CPU["ProcessorId"].ToString();
   break;
  }

  return output;
 }

 public string Manufacturer
 {
  get { return manufacturer; }
 }

 public UInt32 ClockSpeed
 {
  get { return clockSpeed; }
 }

 public UInt16 Family
 {
  get { return family; }
 }

 public string Version
 {
  get { return version; }
 }

 public string ProcessorId
 {
  get { return processorId; }
 }
}
ti - 25 May 2007 15:01 GMT
Thanks Miroslav.

But I think I need to use GetLogicalProcessorInformation().
Because WMI doesn't give me necessary information as far as I checked.

I'd like to know about the relationship between processor-cores like
below examples.

1. whether core-a and core-b share the same L2-cache.
2. whether core-a, core-b, core-c and core-d are in the same
die(physical processor chip).

I believe one of the best ways is to use
GetLogicalProcessorInformation().

I assume the environment is Vista or future release of windows.
And the necessary platforms are x86, x64 and Itanium, so I guess I
also can't use __cpuid().

Best Regards,
TI

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.