C 指针是指向物理地址还是虚拟地址 [英] Does a C pointer refer to the physical or virtual address

查看:85
本文介绍了C 指针是指向物理地址还是虚拟地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 C 语言中为 PC 程序使用指针时,它是指向变量的物理地址还是虚拟地址?

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;

推荐答案

视情况而定.

如果您正在编写一个将在操作系统之上运行的应用程序,即在用户模式下并且操作系统使用虚拟内存,它将指向一个虚拟地址(或者更确切地说,它将指向一个物理地址,但与实际使用的物理地址不同).

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.

这篇关于C 指针是指向物理地址还是虚拟地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆