Memorky Layout and Allocation
来源:互联网 发布:什么是客户端编程 编辑:程序博客网 时间:2024/05/21 04:24
Lecture 5 Memorky Layout and Allocation
使用静态内存分配方式的不一定都是静态变量, 也可能是全局变量
但静态变量一定是静态内存分配
int a;
int b = 1;
static int c; //静态全局变量:只在文件内使用
static int d = 1;
char *str = "str";
static char *str1 = "str1";
void func() {
int e;
int f = 1;
static int g; //静态局部变量:只在函数内使用, 函数执行完后并不释放, 可供下次调用函数时使用
static int h = 1;
char *str2 = "str2";
static char *str3 = "str3";
int *p = (int *)malloc(sizeof(int));
}
Linux的内存布局
(1)全局区和静态区
初始化:
初始化的全局变量b : 0x80495ec
初始化的静态全局变量d : 0x80495f0
全局字符串str : 0x80495f4
全局静态字符串str1 : 0x80495f8
局部静态字符串str3 : 0x80495fc
初始化的静态局部变量h : 0x8049600
未初始化: 系统自动赋予0
未初始化的静态全局变量c : 0x8049610
未初始化的静态局部变量g : 0x804960c
未初始化的全局变量a : 0x8049614
(2)栈区
局部变量:
未初始化的局部变量e : 0xbfd36fdc (使用未初始化的局部变量可能出错,因为它的值是随机的)
初始化的局部变量f : 0xbfd36fe0
局部字符串str2 : 0xbfd36fe4
(3)字符串常量区
字符串常量:
全局字符串str的内容 : 0x80484c0
全局静态字符串str1的内容 : 0x80484c4
局部静态字符串str3的内容 : 0x80484c9
局部字符串str2的内容 : 0x80484ce
(4)堆区
动态分配的内存地址p: 0x8e91008
(5)程序代码区
Windows的内存布局
(1)全局区和静态区
初始化:
初始化的全局变量b : 0x00417000
初始化的静态全局变量d : 0x00417004
全局字符串str : 0x00417008
全局静态字符串str1 : 0x0041700c
局部静态字符串str3 : 0x00417014
初始化的静态局部变量h : 0x00417010
未初始化: 系统自动赋予0
未初始化的静态全局变量c : 0x00417160
未初始化的静态局部变量g : 0x00417164
未初始化的全局变量a : 0x0041718c
(2)栈区
局部变量:
未初始化的局部变量e : 0x0012fe8c (使用未初始化的局部变量可能出错,因为它的值是随机的)
初始化的局部变量f : 0x0012fe80
局部字符串str2 : 0x0012fe74
(3)字符串常量区
字符串常量:
全局字符串str的内容 : 0x0041574c
全局静态字符串str1的内容 : 0x00415744
局部静态字符串str3的内容 : 0x0041573c
局部字符串str2的内容 : 0x004157b8
(4)堆区
动态分配的内存地址p: 0x00385ee8
(5)程序代码区
- Memorky Layout and Allocation
- DomUs and memory allocation
- Understanding virtual memory and dynamic allocation
- Learning Variational Inference and Latent Dirichlet Allocation
- Layout and Style
- Portait and Landscape Layout
- rails layout and rendering
- Control Initialization and Layout
- Adaptivity and Layout
- Gravity and layout gravity
- [转载]Dynamic Memory Allocation and Fragmentation in C and C++
- EXT之Tab and Layout
- PCB Layout and SI 问答
- Memory Layout And The Stack
- Android: Linear Layout and weight
- Facebook Asynchronous Layout and Rending
- gdb and C memory layout
- ReactNative基础---Layout and Flexbox
- 拷贝屏幕到位图的函数
- WebService的两种用户验证方式
- 浅析CAN总线技术的现状与未来
- JAVA面试试题(2)--Hibernate
- C# WIN服务实现窗体
- Memorky Layout and Allocation
- 关于程序设计实践
- ACCESS和DBF、EXCEL、CSV的数据库插入查询方法
- JAVA程序员面试题汇总
- 一篇介绍netfilter的非常好的文章
- JS实现横向图片无缝滚动
- 【SIP】OPEN API测试实战源代码
- 小酌~~
- 年底如何写一份让自己升职的年度报告