If C# code is JIT compiled why do I have to choose a target platform in Visual Studio when building?

StackOverflow https://stackoverflow.com/questions/19138907

  •  30-06-2022
  •  | 
  •  

Pregunta

My assumption could be wrong, but I thought that the main advantage of JIT compilation is that allows a single distributable that the JIT compiler will compile for the target machines particular hardware.

If this is true, then why can a target platform be specified when compiling C#?

Thanks.

¿Fue útil?

Solución

Much of the time you don't need to, and the default is okay. However, there are some circumstances where the default Any CPU can cause problems. One example is if you have a dependency on a 32-bit unmanaged dll. If you leave it at Any CPU and try to run this on a 64-bit system, the JITter will build your .Net code into a 64-bit executable, which will then fail to successfully load the 32-bit dependency. There are other cases as well where it's advantageous to be able to specify the platform. Another example is when you're building an application that you know will be used to load very large data sets into memory. If those data sets could exceed the virtual address space available for 32-bit programs, you may need to specify that you're building a 64-bit application.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top