Does a C pointer refer to the physical or virtual

2020-06-17 07:07发布

When I am using a pointer in C for a PC program, does it point to the physical or virtual address of the variable ?

int x = 10;
int* ptr = &x;

标签: c pointers
4条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-06-17 07:39

The question is irrelevant. If there is a virtual memory manager, then you can't see it, and if there is not, then you can't see that either.

查看更多
闹够了就滚
3楼-- · 2020-06-17 07:40

If there is an underlying OS (not taking embedded systems into account), and it is not a special kind of low-level application (drivers, stacks), the address will always be virtual.

查看更多
老娘就宠你
4楼-- · 2020-06-17 07:49

It depends.

If you're writing a application that will run on top of a operating system, that is, in user mode and the operating system uses virtual memory, it will point to a virtual address (or rather, it will point to a physical address but not the same physical address that will in fact be used).

If you're using an operating system without virtual memory or if you're writing (parts) of the kernel code it will point to the physical address.

查看更多
仙女界的扛把子
5楼-- · 2020-06-17 07:59

It depends on your OS!

In Windows and Linux it's typical virtual memory! Also user space application canno't access the memory using physical addresses.

查看更多
登录 后发表回答