Creating a simple Console .NET Core app in Visual Studio 2019 will now default to AnyCPU
platform (without Prefer 32-bit
set, as it was with a .NET Framework app).
Yet if one toggles on the Prefer 32-bit
, the results no longer respect the old logic, whereby an x86 executable would be generated, but instead an x64 is produced.
Some quick code to check:
Console.WriteLine("Initially allocated: {0} bytes", AppDomain.CurrentDomain.MonitoringTotalAllocatedMemorySize);
int noNumbers = 1000000;
object[] objectArray = new object[noNumbers];
Console.WriteLine("Allocated in the end: {0} bytes", AppDomain.CurrentDomain.MonitoringTotalAllocatedMemorySize);
Platform settings (in red) next to the code's output showing the quantity of memory allocated (in orange):
An element inside the object[]
array will take 4 bytes on an x86 platform and 8 bytes on an x64 one. The output clearly shows this is x64 code. VMMap also confirms this find, based on the 64-bit virtual addresses visible within the process (green highlight):
One needs to specifically select x86 as platform to get a 32-bit executable:
Is 64-bit output code being generated when setting Prefer 32-bit
to enabled in Visual Studio a deliberate change ?
Tested on Visual Studio 2019 16.5 on Windows 10 x64