X86 vs X64 vs AnyCPU [closed]

2019-09-22 04:46发布

问题:

Have a little confusion on X86 , X64 and AnyCPU configuration in VS 2008 , vs 2010

Question 01

How come X86 works in 64 bit windows 7 , windows 8 and even the server configuration machines that is in 64 bit OS ?

Question 02

X86 vs X64 vs AnyCPU what are the clear differences ? can any one explain clearly on each one (i.e. X86, X64 and AnyCPU) separately since the web resources I found are confusing.

回答1:

How come X86 works in 64 bit windows 7 , windows 8 and even the server configuration machines that is in 64 bit OS ?

Because of WoW64 (Windows on Windows 64-bit). Bascially it is a 32 bit emulator, which allows you to run 32 bit programs in a 64 bit operating system.

X86 vs X64 vs AnyCPU what are the clear differences ?

X86 is the mode for 32 bit applications, named after the 80x86 series CPUs. A 32 bit application can address 4 GB of memory.

X64 is the mode for 64 bit applications, it's a shortening of the name x86-64 which is the 64 bit mode of the x86 instruction set. A 64 bit application can address 18 PB (petabyte) of memory, which translates to all available memory (for the forseeable future).

The AnyCpu mode allows for compilation to each of the other two modes.

The compilation mode is just an instruction for the JIT compiler for how it is allowed to compile the IL code into machine code. The IL code itself is the same for all modes.



回答2:

Q1: The 64-bit versions of Windows can run both 32-bit (x86) and 64-bit applications, this is why there are two different c:\Program Files and c:\Program Files (x86) folders to keep applications compiled for the two available CPU architectures apart.

Q2: The target CPU flag that you set is an indication that the compiled result of the build is targeted to run on the selected CPU architecture. In this case the AnyCPU means that the application can run in the preferred 32- or 64-bit mode of the operating system. A system that supports 64-bit mode often makes this the preferred mode to run the application. The reason you want to be able to select the mode manually is if you use any Component that is already compiled for a specific architecture the application must use the same architecture as the Component, Components in this case might be COM- or ActiveX Controls.