Difference between physical and virtual memory visual c++?
I am trying to write a custom memory manager and right now I am allocatin开发者_JAVA百科g a global array of bytes like:
char g_retail_memory[512*MB];
When i then look in the resource monitor of Windows 7 it reports that around 512 MBs of virtual memory has been allocated. can someone please explain why I am not getting physical memory? If i use malloc() instead i get physical memory. Am I doing something wrong? In that case, is there a correct way of obtaining physical memory under visual c++?
See http://en.wikipedia.org/wiki/Virtual_memory
All physical memory you allocate will also be virtual memory, because VM is the way the system presents memory to applications in modern operating systems. The reason you may not see some allocations appear as physical could be that the memory has never been used, so the OS didn't actually need to find physical memory for it, but will when/if the memory is first used.
Note that virtual memory's backing physical memory can later "go away" if the OS needs it for another application. This is sometimes referred to as "swapping" or "paging."
精彩评论