0

I am compiling an application with the /LARGEADRESSAWARE switch set, but when running and looking at the taskmanager, the application allocates max. ca. 2.5GB then it fails with memory allocation errors. Is this correct behaviour?

  • 32 Bit Application (of course)
  • 64 Bit OS / Win10
  • Compiled Visual Studio Comunity 2017
  • There is enough OS memory available (16GB)

In the taskmanager i should see the full 4GB. MSDN states "4 GB with IMAGE_FILE_LARGE_ADDRESS_AWARE set" for a 32 Bit process running under a 64 Bit OS here

This is the linker command line (with some paths stripped)

/OUT:"xxx.exe" /MANIFEST /LTCG /NXCOMPAT /PDB:"xxx.pdb" /DYNAMICBASE /LARGEADDRESSAWARE /DEBUG /MACHINE:X86 /SAFESEH:NO /PGD:"xxx.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"xxx.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"xxx" /TLBID:1

Heiner
  • 165
  • 1
  • 11
  • 1
    Possible duplicate of [Application with LARGEADDRESSAWARE flag set getting less virtual memory](https://stackoverflow.com/questions/25424236/application-with-largeaddressaware-flag-set-getting-less-virtual-memory) – Paul R May 31 '17 at 12:22
  • 3
    Task Manager does not show the commit size by default. Both working set and private bytes are meaningless numbers when you have out-of-memory problems. And Task Manager is the worst possible memory profiler you could find :) – Hans Passant May 31 '17 at 13:37

2 Answers2

2

Hans Passant gave a useful answer in his comment. I did not check 'Commit Size', i checked the private bytes and commit size in the task manager shows some 3.5GB memory usage when allocations begin to fail. Thanks!

Heiner
  • 165
  • 1
  • 11
1

Even checking the commit size in Task Manager cannot reveal all possible sources of an OutOfMemoryException, although it was a good guess by Hans Passant.

Here are some examples were it does not work:

  • run an application and reserve 3.5 GB of memory instead of committing it. Very likely that you get an OutOfMemoryException as well, but the commit size column in Task Manager will not help you. In that case you'll need a tool to display the Reserved Size, e.g. VMMap or Process Explorer (use "virtual size" there, which is reserved + committed)

  • write the following very simple .NET program:

    class Program
    {
        static void Main(string[] args)
        {
            byte[] b = new byte[2*1024*1024*1000];
        }
    }
    

    In that case, you neither have committed nor reserved memory that could help you identify the source of the OutOfMemoryException. Here we have a problem of virtual memory fragmentation.

Some debuggers can help you analyzing OutOfMemoryExceptions.

Screenshot of a program that reserved 2 GB and has only 12 MB committed:

Reserved memory in VMMap

Reserved in Process Explorer

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222