Compiling C# with Any CPU sets Application can handle large (>2GB) addresses
Asked Answered
U

1

7

I ran into this issue during performance testing.

When compiling a C# Console application with the x86 platform flag, the Large Address Aware flag is not set:

Output from dumpbin /headers app.exe:

Dump of file app.exe

PE signature found

File Type: EXECUTABLE IMAGE

FILE HEADER VALUES
             14C machine (x86)
               3 number of sections
        569F0089 time date stamp Tue Jan 19 21:35:37 2016
               0 file pointer to symbol table
               0 number of symbols
              E0 size of optional header
             102 characteristics
                   Executable
                   32 bit word machine

When setting the flag to "Any Cpu" the resulting exe is Large Address Aware:

Dump of file app.exe

PE signature found

File Type: EXECUTABLE IMAGE

FILE HEADER VALUES
             14C machine (x86)
               3 number of sections
        569F01D7 time date stamp Tue Jan 19 21:41:11 2016
               0 file pointer to symbol table
               0 number of symbols
              E0 size of optional header
              22 characteristics
                   Executable
                   Application can handle large (>2GB) addresses

Notice that the "Application can handle large (>2GB) addresses" flag is set.

I cannot find any documentation on this subject. All other stack overflow questions suggest you must do this manually:

How to enable IMAGE_FILE_LARGE_ADDRESS_AWARE in C# source code?

Can I set LARGEADDRESSAWARE from within Visual Studio?

Use the 3Gb of memory in 32 bits applications

The question is: Where is this documented?

Uppity answered 20/1, 2016 at 16:44 Comment(4)
No where afaik. It is fixable, odd that you are not interested in solutions.Roseline
@HansPassant, it's not necessarily a problem (for us), just very unexpected. And the fact that it's undocumented makes it a pain.Uppity
The closest thing I can find to documentation from a primary source is this blog post, blogs.msdn.com/b/calvin_hsia/archive/2010/09/27/10068359.aspx.Dement
FYI, Visual Studio 2013 did not do this, it's new in 2015.Theron
R
4

The purpose of AnyCPU is to be able to run managed code on both x86 and x64 platforms while at the same time take advantage of the larger address space of x64 platforms. The only way to do this is to mark the binary as large address aware when targeting AnyCPU. In addition, if this was not the case, it would have not been appropriate to make Prefer 32-bit the default.

Where is this documented?

This has not been explicitly documented, it's implied.

All other stack overflow questions suggest you must do this manually

Irrespective of all of those questions and answers, this is required only when targeting x86.

Reticulation answered 22/1, 2016 at 11:59 Comment(1)
Making Prefer 32-bit the default was done in VS2012. Making it also set the LARGE ADDRESS AWARE flag is only as of VS2015.Theron

© 2022 - 2024 — McMap. All rights reserved.