Are there any advantages to compiling an assembly as x64?

人盡茶涼 提交于 2019-12-08 20:15:46

问题


Suppose I have a .Net Framework 3.5 SP1/CLR 2.0 application which needs to run on both x86 and x64 platforms. Suppose as well that for whatever reason, I need to create separate x86 and x64 installation programs.

As I have an x64-specific installer anyway, would there be any benefit to recompiling the application itself as x64 rather than targeting "AnyCPU"?

Does setting the target to x64 change anything at all besides the header information of the generated assembly?


回答1:


If you specify x64 it changes some default memory settings for the program, making it slightly more performant in programs with a large memory pressure. Larger thread stacks are allocated when compiling with x64 (link)




回答2:


As long as you are not Ngen'ing any assemblies it would be better to leave as "AnyCPU", and let the JIT target the architecture.




回答3:


I've found than when I wrap a native x86 dll the wrapper assembly needs to be compiled for the x86 platform, otherwise I get a BadImageFormatException thrown on a x64 machine. Then it kind of snowballs, since all assemblies referencing that assembly also needs to be compiled for the x86 platform.

It could be that I'm just doing something wrong, but this is what I've found. If I wasn't using native dlls then I would leave all my assemblies as "AnyCPU".




回答4:


I don't know much about .net assemblies, but in general, if you know that a program will only be executed in x64 architectures, compiling it in x64 machine code you'll get some performance improvement, and you will lose nothing (as long as you already know that it will only be executed in x64 environments).



来源:https://stackoverflow.com/questions/961891/are-there-any-advantages-to-compiling-an-assembly-as-x64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!