You need to lock the memory. While you are only backing it up, you have allocated "virtual memory". You are reading or writing memory. With your program, just add
void* p = malloc(mem); if (p) { std::cout << "memory allocated" << std::endl; memset(p, 0, mem); } else { std::cout << "cannot allocate memory" << std::endl; }
On the Windows operating system, you can use the VirtualQuery function to find out which memory blocks are reserved and what has been done.
source share