是物理内存地址还是虚拟内存地址的问题?

csdnone 2005-12-06 04:59:01

系统是Windows2000,

比如说:
int a = 100;
&a 取得是物理内存地址还是虚拟内存地址?如果是虚拟内存地址,那我怎么取得它的物理内存的地址?

书上说 &a 是“在内存中的实际地址”,可是有人却说“只能取得虚地址,不可能取得实际地址”,到底怎么回事啊?我都晕了

谢谢各位
...全文
303 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdnone 2005-12-07
  • 打赏
  • 举报
回复

我现在认为我们访问到的(无论是在开发环境中看到的,还是程序运行后访问的)都是虚拟地址(就是4GB中的地址),实际的物理地址我们访问不到,还有一些内存方面的api函数求出的地址也都是虚拟地址。而实际地址的映射有cpu或者是windows2000来做,我们作不了,也不知道这样理解对不对!

感谢各位指点,我再研究研究,谁还有高见再说说阿

多谢多谢!
nxnh 2005-12-06
  • 打赏
  • 举报
回复
这么简单的问题竟然也没有几个说对的,程序运行时只能看到逻辑地址,根本看不到物理地址.如果int *x = &a;指的是物理地址,那过一会a被换页换到别的地方了x还指哪啊.楼上的给出的那堆英文跟这问题一点关系没有,不知道贴出来干什么
DrSmart 2005-12-06
  • 打赏
  • 举报
回复
晕死,为什么不看看msdn,没什么可争的
The unary address-of operator (&) takes the address of its operand. The operand of the address-of operator can be either a function designator or an l-value that designates an object that is not a bit field and is not declared with the register storage-class specifier.

The address-of operator can only be applied to variables with fundamental, structure, class, or union types that are declared at the file-scope level, or to subscripted array references. In these expressions, a constant expression that does not include the address-of operator can be added to or subtracted from the address-of expression.

When applied to functions or l-values, the result of the expression is a pointer type (an r-value) derived from the type of the operand. For example, if the operand is of type char, the result of the expression is of type pointer to char. The address-of operator, applied to const or volatile objects, evaluates to const type * or volatile type *, where type is the type of the original object.

When the address-of operator is applied to a qualified name, the result depends on whether the qualified-name specifies a static member. If so, the result is a pointer to the type specified in the declaration of the member. If the member is not static, the result is a pointer to the member name of the class indicated by qualified-class-name. (See Primary Expressions for more about qualified-class-name.) The following code fragment shows how the result differs, depending on whether the member is static:

huangjianmin 2005-12-06
  • 打赏
  • 举报
回复
不过内存分配是非常灵活的,不同版本的操作系统采用的分配方式一般有区别.甚至从后面往前面分配(表现为内存块号由大到小)的都有.
huangjianmin 2005-12-06
  • 打赏
  • 举报
回复
这是操作系统关于内存分配的典型问题呀
WIN2000支持段页式管理,你的int A必然被分配到栈上去.
栈是内存上的一块,当你的程序占内存很小或者你的内存本来够大的情况下,它在内存上.
否则,它就是外存上(硬盘),此时的硬盘也就是所谓的虚拟内存.
当用&a去取地址,取到的是实际的地址.这个不难判断,你可以建一个非常小的程序,如
#include <iostream.h>
int main(void)
{
int a=0;
cout<<&a<<endl;
}
这时你会发现,输出来的十六进制数还是比较大的.
而如果是相对地址,应该是个非常小的数,因为系统为进程分配内存时,相对地址是从0开始的.
但这个实际地址在内存还是虚拟内存中呢,不可确定.
呵呵,这是我在CSDN上回答别人的第一个问题.
wenkui 2005-12-06
  • 打赏
  • 举报
回复
个人觉得是虚地址,不然如果换页就麻烦了 呵呵 找不到了。
xiangding 2005-12-06
  • 打赏
  • 举报
回复
不是物理地址吧,是虚地址吧,
kelinwang19 2005-12-06
  • 打赏
  • 举报
回复
是物理地址吧??
菲斯可儿 2005-12-06
  • 打赏
  • 举报
回复
那文章不错~
hjunxu 2005-12-06
  • 打赏
  • 举报
回复
http://www.aspx.cn/html/program/vc/500/49430.html
hjunxu 2005-12-06
  • 打赏
  • 举报
回复
http://www.ttud.com/info/964.htm
----------------
自己去google吧。
hjunxu 2005-12-06
  • 打赏
  • 举报
回复
当然是虚拟地址了。
要得到物理地址需要做些计算。
HelloIvan2005 2005-12-06
  • 打赏
  • 举报
回复
是物理地址, 可能你每次运行的结果都不一样。
相对地址的话,你每次去出来的都是一样的,是相对进程基地址
HelloIvan2005 2005-12-06
  • 打赏
  • 举报
回复
这样取出来得实物理地址

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧