In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
The main purpose of this article is to show you "what is the use of CAccord Craft + Stack stack and Heap heap". It is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn "what is the use of CAccord Craft + Stack stack and Heap heap".
Overview
A stack is the memory space that flows out for a thread of execution. A head is the space reserved for dynamic allocation.
Stack and heap in program running
Let's take a piece of code as an example:
# include using namespace std;int a = 0; / / Global initialization area char * pt; / / Global uninitialized int main () {int b; / b in stack area char s [] = "abc"; / / s in stack area char * p1; / / in stack area char * p2 = "123"; / / "123" in constant area, p3 in stack area static int c = 0 / / Global static initialization zone char * p3 = new char (65); / / in the reactor area char * p4 = new char [10]; / / in the reactor area return 0;}
Stack area: the stack area is the space for allocating local variables, at a relatively high address. Stack address grows downwards
Heap area: used to allocate memory space applied by female programmers, which is growing upwards.
Static data area: space for assigning static variables, global variables
Read-only area: assigning constants and program code
The difference between heap and stack
Application method and recovery method
Stack: the space on the stack is automatically allocated and reclaimed. The life cycle is released only during the run of the function.
Heap: the space that female programmers apply for according to their needs, as long as female programmers do not release the space, they can always access it. Once you forget to release it, it will cause a memory leak.
Response of the system after application
Stack: as long as the remaining space of the stack is larger than the applied space, the system will provide memory for the program, otherwise the exception prompt stack will overflow. The response speed is fast.
Heap: when the system receives an application from the program, it traverses the linked list of free memory addresses. Look for the first heap node whose space is larger than the applied space. The response speed is slow.
Application efficiency comparison
Stack: automatically allocated by the system, faster, female programmers can not control.
Heap: allocated by new, it is generally slow and prone to memory fragmentation, but is the most convenient to use.
Limit the size of the application
Stack: under Windows, the size of the stack is 2MB. If the requested space exceeds the remaining space in the stack, overflow will be prompted
Stack overflow.
Heap: the size of the heap is limited by the virtual memory available in the computer system. The space obtained by the heap is more flexible and larger.
Storage in heaps and stacks
Stack: the address of the next executable statement of the function call statement, the parameters of the function, and the local variables in the function.
Heap: the specific content will be arranged by the female programmer.
Note: when there is a pointer data member, you must use deep copy to make it use the space of the heap area.
The above is all the content of the article "what is the use of stack stack and heap heap in Cumberbatch +? thank you for reading!" I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.