Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
内存分配模式-Linux_Linux - Fatal编程技术网

内存分配模式-Linux

内存分配模式-Linux,linux,Linux,我对linux系统中的内存分配模式非常困惑..为了理解我编写了一个简单的程序,我在下面列出了: main() { int a=5; char b='B'; int c=10; int *p=NULL; char *q=NULL; int *r=NULL; p = new int; q = new char; r = new int; printf("\n The address of a : %p ",&a); printf("\n The address of

我对linux系统中的内存分配模式非常困惑..为了理解我编写了一个简单的程序,我在下面列出了:

main()
{  
 int a=5;
 char b='B';
 int c=10;
 int *p=NULL;
 char *q=NULL;
 int *r=NULL;
 p = new int;
 q = new char;
 r = new int;
 printf("\n The address of a : %p ",&a);
 printf("\n The address of b : %p ",&b);
 printf("\n The address of c : %p ",&c);
 int *p=NULL;
 int *q=NULL;
 p = new int;
 q = new int;
 printf("\n The address of a is %p ",&a);
 printf("\n The address of b is %p ",&b);
 printf("\n The address of p : %p ",&p);
 printf("\n The address of q : %p",&q);
 printf("\n The address at which new1 memory is allocated :  %p ",p);
 printf("\n The address at which new2 memory is allocated :  %p ",q);
 }
在Red Hat Linux 7.3 X86 PC上的输出:

The address of a : 0xbffffa74
The address of b : 0xbffffa73
The address of c : 0xbffffa6c
The address of p : 0xbffffa68
The address of q : 0xbffffa64
The address of r : 0xbffffa60
The address at which new1 memory is allocated :  0x8050638
The address at which new2 memory is allocated :  0x8050648
The address at which new3 memory is allocated :  0x8050658
下面是我的一些问题,请帮助我理解

1.为什么堆栈上的c和b之间有7个字节的差异

2.为什么堆上分配的每个变量有10字节的差异

3.每当我运行此可执行文件时,我都会得到相同的地址..这怎么可能


请帮助我理解这种行为

您正在打印指针的地址…您好@OliCharlesworth。。你指的是哪条线?首先,我打印指针的地址,然后在动态内存分配后,我打印指针的内容..哪个inturn将是新运算符的地址。。请澄清..1所需的对齐约束2分配器通常为维护堆3标准化进程内存地址空间layoutHi@twalberg.所需的特定于分配器的内部元数据分配多于请求的内容。。谢谢你的答复。。是否有可供参考的理论?我想去学习那些概念?它是操作系统的一部分吗?最好的理论可能是你的C库的源代码。。。也许x86/x86_64程序员参考手册。。。以及Linux内核源代码/文档。。。