当前位置:网站首页>The memory four area model of C language program
The memory four area model of C language program
2022-06-12 03:48:00 【Embedded workplace】
Catalog
1、 Memory four area model flow of program
4、 Global area (global) or static( Static zone )
1、 Memory four area model flow of program

- The operating system puts the physical hard disk code load To the memory
The operating system puts c The code is divided into four areas
The operating system found main Function entry execution
2、 Heap area (heap)
Release is usually assigned by the programmer ( Dynamic memory release and application ), If programmers don't release , At the end of the program , May be recycled by the operating system .
First of all, you should know that the operating system has a list of free memory addresses , When the system receives an application for a program , Will traverse the table , Find the first heap node whose space is larger than the applied space , Then delete the node from the free node list , And allocate the space of the node to the program , in addition , For most systems , The size of this allocation will be recorded at the first address in this memory space , such , In code delete Statement can correctly release the memory space . in addition , Because the size of the heap node found is not necessarily exactly the size of the request , The system will automatically put the extra part back into the free list .
The heap is made up of new Allocated memory , Generally speaking, it's slow , And it's prone to memory fragmentation , But it's the most convenient .
It needs to be assigned by the programmer , Such as :
ch = (char *)malloc(20); // The distribution of 20 The byte area is the heap area
stay C++ in :
p = new char[10];
3、 The stack area (stack)
Release is automatically allocated by the compiler , Store function parameter values , Local variable value ;
As long as the remaining space of the stack is larger than the requested space , The system will provide memory for the program , Otherwise, an exception will be reported indicating that the stack overflows .
Stacks are allocated automatically by the system , Faster . But programmers can't control it .
for example :
Declare the local variables in the function :int m; The system makes room for it in the stack .
4、 Global area (global) or static( Static zone )
Global variables and static variables are stored together , Initialized global variables and static variables are in the same area .
Uninitialized global variables and uninitialized static variables are in another adjacent area .
This area is recycled by the operating system after the program runs .
5、 Code section (code)
Store the binary code of the function body ;
6、 Specific examples
#include <stdio.h>
#include <stdlib.h>
int a = 4; // Global initialization area
char *ch; // Global uninitialized area
int main() {
int m; // Stack
char *p; // Stack
char *p3 = "123"; // 123/0 In the constant area ,p3 On the stack
static int n = 12; // Global initialization area
p = (char *)malloc(sizeof(char)); // The allocated byte area is the heap area
ch = (char *)malloc(20); // The distribution of 20 The byte area is the heap area
return 0;
}边栏推荐
- MySQL创建用户并授权
- 基于SSH实现健身俱乐部管理系统
- 【FPGA混沌】基于FPGA的混沌系统verilog实现
- Emperor Wu of Wei knew that he could not correct it, so he stopped offering his words
- 【C语言】变量本质分析
- 电商中台系统架构
- Mongodb essence summary
- JSP实现银柜台业务绩效考核系统
- Plot visualization in R language: visualize the scatter diagram of the actual value and the predicted value of the regression model, analyze the prediction efficiency of the regression model, distingu
- Notes relatives à l'application du certificat de l'AC et de la paire de clés
猜你喜欢

Drop down menu dropdown yyds dry inventory of semantic UI

How do I make the mouse wheel work in the VB6 ide- How can I make mousewheel work in VB6 IDE?

顺序表与链表---初阶

【C语言】变量本质分析

Hudi of data Lake (14): basic concepts of Apache Hudi

In 2022, don't you know the difference between arrow function and ordinary function?

(idea)the file size(2.85M) exceeds configured limit(2.56M).Code insight features are not available问题

Steamvr--- grab objects

【FPGA+FFT】基于FPGA的FFT频率计设计与实现

2022 communication industry ultimate Exhibition Guide
随机推荐
Redis gets the set of keys prefixed with XXX
[Yugong series] March 2022 asp Net core Middleware - cross domain
Solution to missing in unity script
What does hard work mean to you?
MySQL的check约束数字问题
Message queuing overview
Go 语法 变量
E-commerce middle office system architecture
php和js去掉所有空格
成功解决:WARNING: There was an error checking the latest version of pip.
Naive Bayes classification of scikit learn
动规(15)-最低通行费
Goodbye to excel and PPT, I found a better visual fool software
The road of global evolution of vivo global mall -- multilingual solution
[Business Research Report] analysis report on online attention of China's e-sports industry in 2021 - download link attached
How to have peace of mind? Get a new heart
[mysql][mysql 8.0 compressed package installation method]
Drop down menu dropdown yyds dry inventory of semantic UI
Yyds dry inventory MySQL learning - how transactions are isolated
Implementation of fitness club management system based on SSH