当前位置:网站首页>【嵌入式】---- 内存四区介绍
【嵌入式】---- 内存四区介绍
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 中存储一份
边栏推荐
- Socket TCP for network communication (I)
- Dynamically monitor disk i/o with ZABBIX
- Master and backup role election strategy in kept
- Swagger
- [combinatorics] permutation and combination (summary of permutation and combination content | selection problem | set permutation | set combination)
- Symlink(): solution to protocol error in PHP artisan storage:link on win10
- Solve msvcp120d DLL and msvcr120d DLL missing
- (构造笔记)GRASP学习心得
- New features of ES6
- Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
猜你喜欢

Wechat applet - basic content

Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022

XML (DTD, XML parsing, XML modeling)

OpenGL 索引缓存对象EBO和线宽模式

Vulnhub geminiinc

OpenGL index cache object EBO and lineweight mode

网络通讯之Socket-Tcp(一)

OpenGL draws colored triangles

ES6新特性

【mysql官方文档】死锁
随机推荐
Develop plug-ins for idea
Vulnhub geminiinc
网络通讯之Socket-Tcp(一)
(database authorization - redis) summary of unauthorized access vulnerabilities in redis
PHP导出word方法(一phpword)
Vulnhub geminiinc V2
(构造笔记)ADT与OOP
DEJA_ Vu3d - cesium feature set 053 underground mode effect
Ripper of vulnhub
Dart: view the dill compiled code file
DEJA_ Vu3d - 054 of cesium feature set - simulate the whole process of rocket launch
[official MySQL document] deadlock
Download address and installation tutorial of vs2015
Groovy test class and JUnit test
Ripper of vulnhub
Summary of development issues
232. Implement queue with stack
023 ([template] minimum spanning tree) (minimum spanning tree)
Swagger
Sheet1$. Output [excel source output] Error in column [xxx]. The returned column status is: "the text is truncated, or one or more characters have no matches in the target code page.".