createfilemapping size constraints

GF 21 Reputation points
2025-03-04T02:09:26.1233333+00:00

What is the maximum size that can be used with CreateFileMapping with INVALID_HANDLE_VALUE and SEC_RESERVE, for a virtual paged memory backed file, on windows 11 with 32 gb physical memory I can specify for example 64 gb but on windows 2016 it seems limited to about 4 gb (from a 32 bit program but it shouldn't matter since it's done by the o.s.) are there any limitations on size allocatable, should paging file be turned on or what caveats ?.

It seems to happen on a vmware hosted W2016, with say 8-10 gb ram allocated, but not on physical W11, could there be any CreateFileMapping constraints specific to windows as guest vm, that the o.s. detects being hosted and perhaps restricts size, I have the page file set to auto.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,741 questions
{count} votes

Accepted answer
  1. RLWA32 47,521 Reputation points
    2025-03-08T09:04:03.0333333+00:00

    Give this a try -

        ULARGE_INTEGER uli{};
        uli.QuadPart = (ULONGLONG)1024 * 1024 * 1024 * 8; // 8 gb
    
        HANDLE heap = CreateFileMapping(INVALID_HANDLE_VALUE,
            NULL,// security
            PAGE_READWRITE | SEC_RESERVE,
            uli.HighPart, // hi
            uli.LowPart,// lo
            NULL);
    
        return 0;
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.