VirtualAlloc MEM_COMMIT and MEM_RESERVE

I'm a little confused with VirtualAlloc,

We can reserve the memory usage of MEM_RESERVE and then commit it with MEM_COMMIT, but I'm a little confused about what the difference is when using between the two functions below:

m_pvData = VirtualAlloc(NULL, m_nBuffSize, MEM_COMMIT, PAGE_READWRITE);
m_pvData = VirtualAlloc(NULL, m_nBuffSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

What is the benefit of choosing the second option?

And I can use the function below to get the buffer:

void* pdata = VirtualAlloc(NULL, 64*1024*1024, MEM_COMMIT, PAGE_READWRITE);
if (pdata == NULL)
{
    cout<<"Last error is "<<GetLastError()<<endl;
}

Error

+4
source share
1 answer

The difference is this: with MEM_RESERVEyou basically say to the operating system: "Hey, please, I need this continuous block of pages of virtual memory, can you give me a memory address that suits my needs?"

, . . ( , , , "Windows Internals 5th" - : Google VAD).

, , "node" - โ€‹โ€‹, , , , VirtualAlloc().

, MEM_COMMIT, . , . , , , .

. , / ( -). .

2. , OR MEM_RESERVE|MEM_COMMIT, - , API- VirtualAlloc(), .

3. MEM_COMMIT , MEM_RESERVE MEM_RESERVE|MEM_COMMIT + , , 64 Windows . , GetSystemInfo().

+5

All Articles