Is there a constraint to the size of arrays for the NEW operator?

Joseph Klasen 146 Reputation points
2022-08-20T03:43:56.843+00:00

Assuming a workstation with 128 GB of ram, what is the maximum array size that Windows will accept in say:

BYTE* ByteArray;

ByteArray = new BYTE[XXXXX};

Assuming say 100GB is available on the heap, is there a constraint to the value of XXXXX in this example?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,526 questions
{count} votes

Accepted answer
  1. WayneAKing 4,921 Reputation points
    2022-08-20T05:54:58.92+00:00

    Memory limitations for processes are based on virtual memory,
    not physical memory (RAM).

    The max memory available for a given process depends on whether
    it is x86 or x64, which version of WIndows the process is running
    under, whether or not the program was built with

    IMAGE_FILE_LARGE_ADDRESS_AWARE

    set or cleared, etc.

    See:

    Memory Limits for Windows and Windows Server Releases
    https://learn.microsoft.com/en-us/windows/win32/memory/memory-limits-for-windows-releases

    Within these constraints, the max size that a dynamic allocated array
    can have depends on how much of the process's memory space is available considering all other demands on that space. Code, other dynamic allocations, etc. all deplete the available heap.

    Note that allocating all of the available heap via new[], malloc,
    etc. can result in other parts of the program failing later when
    an attempt is made to acquire space from the heap. This may occur
    within library code such as expanding class objects such as
    vectors, lists, maps, strings, etc.

    • Wayne

0 additional answers

Sort by: Most helpful