views:

114

answers:

5

Hi,

What does the address in a pointer refer to, real address location in main memory or virtual address. Can it be configured.

And if it refers to virtual address , does Memory manager needs to convert this address to real address everytime it is accessed

+5  A: 

If your system uses VM, then the address is virtual, if it doesn't, it isn't. This has nothing to do with either C or C++.

anon
-1 for pedantry that doesn't contribute anything and doesn't make an effort to find out what the questioner is trying to ask.
Edmund
I don't see useless pedantry, pointing out that this is independent from the programming language is a valid and to some enlightening remark.
Frank
+10  A: 

This depends on your system and OS.

For a typical windows/linux user space application, the address is a virtual memory address. User space applications have no way of accessing the memory using physical addresses - that's one of the abstractions the OS gives each process.

The MMU(Memory management unit) does this translation for every memory access, and it's up to the OS to set up the corect mapping for your process.

nos
On Linux a user space application can read and map physical memory through /dev/mem. Obviously, it has to be a privileged application, still though in user space. http://lwn.net/Articles/147901/
Maxim Yegorushkin
+1  A: 

In other words, as a developer/programmer, you don't have to worry about whether the address is virtual or real. Pointer works perfectly in all the cases.

Except if you are managing memory-mapped IO, etc...
Oli Charlesworth
+1  A: 

In some OS you are interacting with actual physical addresses e.g. in the old MS-DOS/Apple ][ OS you could poke around directly in the actual graphics memory. However this had the limitation that your program was stuck in a certain place in memory. A bit simplified modern OS have a memory manager that typically shields the application from the actual physical memory, this enables the OS to handle multiple processes in a more effective way and allowing apps virtual memory.

Anders K.
+1  A: 

On a real operating system with virtual memory, of course it can't be configured, because normal processes don't have permission to peek and poke at physical memory; they only see virtual memory.

R..