Sunday, December 30, 2012

Detect CPU architecture at runtime for Windows 8 Store Apps

  If you are developing an application for the Windows 8 Store it is very important that you test it on an ARM device (Surface RT, Asus VivoTab RT, Dell XPS 10,etc.) before sending it into certification. You will probably have some bad surprises and not everything that was fast&fluid on your development machine will continue to be so on an ARM device (the list scroll performance reminds me of the first version of Windows Phone). So you will have to simplify the layouts, animations and in some cases even rewrite part of your code. Parallel Programming is your friend if you can use it (for Kids' Orchestra I had the big problem that generating 100ms of sound output took more then 100ms so after 2 days of trying to optimize the C# source code I realized that I only had to use the Parallel.For and everything started working). 
   Due to performance differences you might need to split the user experience/code on different architectures (like disabling some animations on ARM). If this is the case it becomes very important to know the processor architecture on which your application runs. One solution would be to create 3 different packages of your applications and use the conditional compilation to differentiate between what happens on each architecture. If you still want to use only one package (Any CPU) it is enough to have a method that returns the processor architecture.
    The bad news is that WinRT framework doesn't have any method/property that returns the processor architecture  (at least I don't know it). The good news is that you can still use GetNativeSystemInfo as it is an api supported for Windows Store apps (it is even supported for Windows Phone 8 apps):

  For Windows Store apps you can use two approaches to call this api:
1. Use P/Invoke -this is the one I opted for;
2. Create a Windows Runtime Component in C++ that you can then call from managed code - this is the approach you will have to use if you need to call this function on Windows Phone 8.

   What I did is to create a public class, which I called CPU, and has one public static property NativeInfo that returns an SystemInfo object:

 public class SystemInfo  
     public ProcessorArchitecture ProcessorArchitecture;  
     public ushort ProcessorArchitectureId;  
     public ProcessorType ProcessorType;  
     public uint ProcessorTypeId;  
     public uint NumberOfProcessors;  
     public ushort ProcessorLevel;  
     public ushort ProcessorRevision;  
     public uint AllocationGranularity;  

and a public method IsProcessorFeaturePresent (invoking also a supported Api for Windows Store applications) which returns if a certain ProcessorFeature feature is supported or not.

I have also created a small sample that will give you a list with your processor details. Here is the result I got on  my Surface:

Hope you will find the class useful. Don't hesitate to contact me if you need further details.




  1. Great post. It is very helpful information for all the mobile developers. I got excellent things from it. Keep it up. Thanks for nice stuff.

    Mobile Developer

  2. Thanks for the blog, great tips and information. Thanks for sharing.Inspiritysoft

  3. Here is a database compatible with Windows Runtime:

  4. I did not check before submitted!! I will be very helpful from the software by which I can check the newly built apps. This post is very helpful for the apps builders as well as for the mobile developer.
    find good apps

  5. Rize has developed innovative concepts for Windows 8 apps development. Having apps in Windows platform will increase accessibility to customers as Windows 8 comes with built-in apps to help users.

  6. It is extremely of service data about points of interest of PHP for Custom Web Application Development for all and it is exceptionally easy to get it. Much obliged concerning offering it.window phone apps // iPhone application development // mobile app developers