[英]C++ 64 Bit machine , shows 32 Bit heap address
I created a sample C++ program on a 64 Bit linux machine running on VMware Player over host machine as windows. 我在通过主机作为窗口在VMware Player上运行的64位linux计算机上创建了一个示例C ++程序。 The below is a class code. 下面是一个类代码。
class operatorOverloadingTest{
private:
int age;
char *name;
public:
operatorOverloadingTest(int age){
this->age = age;
name = new char[10];
strncpy(name,"Indra",strlen("Indra"));
}
void displayDetails(){
cout<<"My Name :"<<name<<endl;
cout <<"My age: "<<age<<endl;
}
friend ostream & operator<<(ostream &out, const operatorOverloadingTest &myObj);
~operatorOverloadingTest(){
delete name;
cout<<" \nDestructor getting called"<<endl;
}
};
In my Main function, created object of class:
1. By using new operator.
2. Stack Object.
int main(){
operatorOverloadingTest *oOT = new operatorOverloadingTest(10);
operatorOverloadingTest oOT1(30);
I understand that, on 64-Bit machine, memory address are represented in 8 Bytes. 我了解在64位计算机上,内存地址以8字节表示。
When I run the program using GDB, i see the below address: 当我使用GDB运行程序时,我看到以下地址:
p oOT
$1 = (operatorOverloadingTest *) 0x613c20
p &oOT
$2 = (operatorOverloadingTest **) 0x7fffffffe228
&(oOT1.age)
$7 = (int *) 0x7fffffffe210
(gdb) p &(oOT->age)
$8 = (int *) 0x613c20
My question is, why does object allocated in heap shows a 32 bit address representation and the object on stack (oOT1) shows a 64 bit address representation though my operating System is 64 Bit? 我的问题是,尽管我的操作系统是64位,为什么在堆中分配的对象显示32位地址表示,而堆栈上的对象(oOT1)显示64位地址表示? (Checked using uname -a). (使用uname -a检查)。
My question is, why does object allocated in heap shows a 32 bit address representation and the object on stack (oOT1) shows a 64 bit address representation 我的问题是,为什么在堆中分配的对象显示32位地址表示,而堆栈上的对象(oOT1)显示64位地址表示
When you look at 0x1234
, you know that the entity has at least 16 bits, but you can't tell whether it's 16-bit, a 32-bit, or a 64-bit entity, because GDB will not print leading zeros. 当您查看0x1234
,您知道该实体至少有 16位,但是您无法确定它是16位,32位还是64位实体,因为GDB不会打印前导零。
If you want to know how big some program entity is, try: 如果您想知道某个程序实体的大小,请尝试:
(gdb) print sizeof(oOT)
(gdb) print sizeof(&ooT)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.