当前位置:网站首页>Summary of static memory allocation and dynamic memory allocation
Summary of static memory allocation and dynamic memory allocation
2022-06-12 18:09:00 【Independent spiritual believers】
Static memory is automatically allocated by the system , Automatically released by the system . Static memory is allocated in the stack , If main Function calls another function , Then press the called function onto a stack . To execute the called function is to make all the memory space allocated by the system for this function out of the stack one by one . The end of the stack is the completion of the execution of the called function .
The order of the stack is "first in, then out" , That is, the post execution of the advanced stack , Because the advanced stack is pressed down , So the execution is always the content at the top of the stack . The completion of program execution means “ All the contents in the stack are out of the stack ”. Out of the stack is “ Release ”. When the top of the stack is all out of the stack, it will become the top of the stack , Then continue to execute the stack contents , Keep going out of the stack . The complete execution of the whole program means “ All memory space allocated by the system is out of the stack ”, All memory has been released . Therefore, the memory space allocated by the system for static variables will be released after the execution of the program .
Dynamic memory is released manually by the programmer , Function termination is not automatically released by the system . This shows that he is definitely not allocated in the stack . Where did he distribute it ? Is in “ In the pile ” The distribution of , Stack is a storage structure , Heap is not a storage structure , Heap is a sort of memory allocation . Also said , Dynamic memory is allocated by heap sorting . Previously, I talked about sorting , Sort like bubbling , Insertion sort , Selection sort , Quick sort . Heap sorting is also a sort method , Because dynamic memory is allocated in the heap , It is allocated in a sort way , Not in the stack , So the function will not be released after running .
Because dynamic memory is allocated manually by the programmer , Hand release , So there will be a serious problem at this time : If you forget to release , Will cause memory leaks , So dynamic memory allocation has advantages , There are also shortcomings. . The use of dynamic memory is very flexible , But there are many problems that need attention .
Memory allocation is a very complicated problem . Now it's just getting started , So don't talk too much .
边栏推荐
猜你喜欢

JDBC quick start tutorial

Global lock, table lock, row lock

Typescript type declaration file (III)

C#简单介绍

Message queuing MySQL tables that store message data

HTTP缓存<强缓存与协商缓存>

Schedule update | 2022 Microsoft and Intel hacker song competition is in hot registration

MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column

TypeScript常用类型(一)

小程序+App,低成本获客及活跃的一种技术组合思路
随机推荐
TypeScript常用类型(一)
极限编程--根源分析实践
Overall flow chart of kernel interrupt
High-Speed Layout Guidelines 未完...
Vant3+ts H5 pages are nested into apps to communicate with native apps
Stack in JS (including leetcode examples) < continuous update ~>
C business serial number rule generation component
The server time zone value ‘� й ��� ʱ ��‘ is unrecognized or represents more than one time zone. ......
Eve-ng installation (network device simulator)
NixOS 22.05安装过程记录
Applet and app are owned at the same time? A technical scheme with both
Byte flybook Human Resources Kit three sides
es7不使用父子和嵌套关系来实现一对多功能
Introduction to reinforcement learning and analysis of classic items 1.3
MySQL learning notes
js快速排序
When openharmony meets openeuler
LCD parameter interpretation and calculation
leetcode491 递增子序列
Relationship between resolution and line field synchronization signal