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)程序代码区
分享到:
相关推荐
Risk and Asset Allocation
Joint Relay Selection and Power Allocation in Cooperative-Diversity System,白皛,,In this paper, we propose two novel algorithms where relay selection and power allocation are jointly considered in ...
Logical Channel Descriptor and Allocation of Logical Channel Numbers
关于Adaptive Prototype Learning and Allocation for Few-Shot Segmentation
06 风险规避与风险资产分配Risk Aversion and Capital Allocation.pptx
covariance matrix and capital allocation
Online Matching and Ad Allocation,谷歌的广告论文欧!
[基于QoS的资源分配与收发机优化]QoS-Based Resource Allocation and Transceiver Optimization
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed ...
Attilio Meucci的风险管理教程(英文原版)
201705Taxation and the Allocation of Talent.pdf
In this paper we examine the question of designing and allocating transmission sequences to users in a mobile ad hoc network that has no spatially boundary. A basic tenet of the transmission sequence ...
Design_and_Implementation_of_GCC_Register_Allocation ........................................................................... ....................................................... ..................
09286771 Dynamic Reserve and Transmission Capacity Allocation in Wind-Dominated Power Systems
VRAA: virtualized resource auction and allocation based on incentive and penalty
Dynamic Storage Allocation A Survey and Critical Review
In this paper, we study the resource allocation algorithm design for multiuser orthogonal frequency division multiplexing (OFDM) downlink systems with simultaneous wireless information and power ...
The flow capturing and the p-median location-allocation models deal quite differently with demand for service in a network. The p-median model assumes that demand is expressed at nodes and locates ...
Resource allocation and cross-layer control in wireless networks
Joint Offloading and Resource Allocation_globecom