开发者

How to optimize .NET applications to 64-bit?

In Visual Studio > Build > Configuration Manager you can choose the target platform.

What does it c开发者_如何学Change?

Is there any other way I can optimize my .NET app when targeting x64 platforms?


As already mentioned, the IL in the .NET assembly is platform independent (that's what the Any CPU setting implies). The JIT (just-in-time) compiler of the .NET runtime will compile this platform independent byte code into platform specific native code with the optimization specific to that platform. So there is normally nothing you should worry about.

However, if you explicitly set your project to be build with x64 as the platform target the assembly will no longer run on an x86 runtime (and vice versa for x86 at the platform target). This is useful only if your code has dependencies to native x64/x86 libraries such as in-process COM components.

As Rowland added in a comment, the platform target must not be confused with the bitness of the underlying operating system. .NET assemblies with x86 as the platform target will run on both 32-bit and 64-bit versions of Windows (i.e. as a 32-bit process in WOW64 mode).

In fact, probably the most common scenario to use the platform target setting is when your .NET assembly has a reference to a 32-bit COM component. To be able to execute the assembly on an x64 system, the assembly must be compiled with the x86 flag. On a 64-bit OS and with the Any CPU setting enabled, the runtime would execute the assembly in a 64-bit process and loading the 32-bit COM component into the 64-bit process would fail. Compiling with the x86 flag causes the .NET runtime to execute the assembly in a 32-bit process and thus the COM component can safely be loaded.


It doesn't "optimize" your app for 64-bit platforms. .NET assemblies will contain IL which is platform-independent by definition regardless of that setting. That setting simply flips a flag in the target assembly and makes it run on the specific version of the runtime.


Your C# / VB.Net etc is compiled into the correct IL for the platform, be it x86, x64 or whatever. There are no separate constucts in the language to direct code down either route, so the answer is no.


The default setup for a .NET application is Any CPU which means the assemblies will run on both 32 and 64 bit platforms. You can however specify either 32 bit or 64 bit to require either a 32 or 64 bit runtime.

Remember the IL code in the assemblies are JIT compiled when the application executes. So a Any CPU assembly will run on both 32 and 64 bit without further ado.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜