当前位置:网站首页>【嵌入式】---- 内存四区介绍
【嵌入式】---- 内存四区介绍
2022-07-03 11:40:00 【伊 娃】
一、内存四区由来
程序执行是跑在内存中的,而程序中不同的对象(如 指针,局部变量,全局变量,函数参数 等等)要求的生命周期是不同的,所以将这些对象放在不同的区段,这样就赋予了这些对象不同的生命周期,内存四区由此而来。
二、内存四区介绍
内存四区分为:栈区,堆区,全局区,代码区。
1. 栈区(stack)
栈区由编译器自动分配和释放。
栈区主要存放函数参数、函数返回值、局部变量。
2. 堆区(heap)
堆区由程序员手动分配和释放。如果程序员未释放,在程序运行结束时,由系统释放。
堆区主要存放由 malloc 关键字申请的内存空间。在C++语言中关键字 new 申请的内存也在堆区。
3. 全局区
全局区又叫数据区或者静态区。
全局区分为三段: data段 、bss段、rodata 段。
(1).data 段存放已初始化和值不为0的全局变量和静态变量
(2).bss 段存放未初始化和初始化值为0的全局变量和静态变量。
(3).rodata 段存放各类常量,如:const、字符串、#define等
data 段又叫 RW-data 段
bss 段又叫 ZI-data 段
rodata 段又叫常量区或只读存储区
4. 代码区(text)
代码区又叫 code 段 或 text 段。
用来存放程序代码,由操作系统进行管理,只读。
三、额外补充
flash 或者 ROM 掉电后数据还是保存的,保存的数据有 RO-data、RW-data、代码区
RAM 一般指的就是 sdram,运行速度快,但是掉电数据会丢失,保存的数据有 栈区、堆区、数据区
注意:
1,flash 或者 ROM 中为什么不保存 ZI-data?
ZI-data 段数据未初始化或初始化为0,在启动系统时直接将这块 flash 或者 ROM 清0即可,无需保存。
2,RW-data 是 RAM 使用的,为什么存储到 flash 或 ROM 中?
RW-data 这部分变量已经初始化了,只存在RAM中掉电会丢失,所以需要在flash 或 ROM 中存储一份
边栏推荐
- 在网上炒股开户可以吗?资金安全吗?
- (construction notes) grasp learning experience
- Vulnhub narak
- Notes on 32-96 questions of sword finger offer
- 242. Effective letter heteronyms
- ES6新特性
- Shell: basic learning
- How to convert a numeric string to an integer
- Wechat applet - basic content
- Kubernetes three dozen probes and probe mode
猜你喜欢
[official MySQL document] deadlock
Why can't my MySQL container start
Vulnhub's Tomato (tomato)
CGroup introduction
win10 上PHP artisan storage:link 出现 symlink (): Protocol error的解决办法
(构造笔记)ADT与OOP
Visual studio 2022 downloading and configuring opencv4.5.5
Quantitative calculation research
Niuniu's team competition
Vulnhub's cereal
随机推荐
Jsup crawls Baidu Encyclopedia
Pki/ca and digital certificate
PHP导出word方法(一mht)
MCDF Experiment 1
OpenGL index cache object EBO and lineweight mode
Optimize interface performance
vulnhub之tomato(西红柿)
Quantitative calculation research
vulnhub之narak
OpenGL 绘制彩色的三角形
Summary of development issues
Vulnhub pyexp
OPenGL 基本知识(根据自己理解整理)
Php Export word method (One MHT)
ES6 standard
232. Implement queue with stack
Why can't my MySQL container start
Itext7 uses iexternalsignature container for signature and signature verification
Duplicate numbers in the array of sword finger offer 03
STL Tutorial 9 deep copy and shallow copy of container elements