0

all, can anybody tell me that how to get a variable's physical address? (OS is Win7 64bit)

like:

void main()
{
    int a=10;
    ........
    return;
}

how can I get the physical address of variable 'a' ?

Nalaka526
  • 11,278
  • 21
  • 82
  • 116
  • I donot think so, you can get a visual address like you just did, but cannot get physical address. – MengLei Dec 30 '13 at 08:19
  • Physical address (not virtual address) of the memory is really low-level stuff. You will need OS-specific syscalls to accomplish that. – WiSaGaN Dec 30 '13 at 08:31
  • Can you say more about OS-specific syscalls, please? – MengLei Dec 30 '13 at 11:38
  • You may find these links helpful: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366781(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/ms810627.aspx – WiSaGaN Dec 30 '13 at 11:48

3 Answers3

2
how can I get the physical address of variable 'a' ?

No, you can't. The address you see refers to the virtual memory address and not to the physical RAM address. The program runs on Virtual memory allocated by the OS. If a process starts executing, a process address space is created for each process where all the information/data resides. For more info on process address space, click here.

Community
  • 1
  • 1
0

in os case &a will print virtual address . virtual addresses are sometime have relations with physical address . to understand the relation of virtual address to physical address you need to understand the MMU of x86 and also windows 7 memory management part

user2760375
  • 2,238
  • 2
  • 22
  • 29
-1

Answer to Your question is &a may give you the Physical Address of variable a but If your code is loaded as part of the operating system and only if your operating system is running on a physical machine.

Note: If your operating system is running on a virtual machine, it will always give you virtual address or If your code is loaded as a regular application on a modern operating system, then also it will be a virtual address (logical address).

batman
  • 267
  • 2
  • 11
  • This has little to do with virtual machines. The virtual memory mechanism is ubiquitous among modern computer architecture. And it is carried out by the coordination of CPU, memory and operating system. – WiSaGaN Dec 30 '13 at 09:16