actually C and C++ There are some differences in the memory partition of , But there is no distinction here :
1), Stack area (stack)— Release automatically assigned by compiler , Store the parameter value of the function , Value of local variable, etc . his
The operation mode is similar to the stack in data structure .
2), Heap area (heap) — Release is usually assigned by the programmer , If the programmer does not release , At the end of the program, the OS return
collect . Notice that it's not the same as the heap in the data structure , The allocation method is similar to the linked list .
3), Global area ( Static area )(static)—, Global and static variables are stored in one block , Initialized
Global and static variables in one area , Uninitialized global variables and uninitialized static variables are in the adjacent
An area . - Released by the system at the end of the program .
4), Text constant area — Here's the constant string . Released by the system at the end of the program .
5), Program code area — Storing binary code of function body .

The difference between stack area and heap area :
1) Storage in heap and stack : Stack local variable , Function parameters, etc . Heap storage usage new,malloc Applied variables, etc ;
2) Application method : Stack memory allocated by system , Heap memory is self requested ;
3) System response after application : Stack —— 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 to indicate stack overflow .

heap —— First of all, you should know that the operating system has a linked list of free memory addresses , When the system receives an application from the program , Will traverse the list , Find the first heap node whose space is larger than the applied space , Then the node is linked from the free node list
Delete from , The space of the node is allocated to the program ;
4) Limit of application size :Windows The size of the next stack is generally 2M, Large heap capacity ;
5) Comparison of application efficiency : Stack is automatically allocated by the system , Faster . Heap usage new,malloc Equal distribution , slower ;
summary : Stack area advantage in processing efficiency , The advantage of reactor area is flexibility ;
Memory model : Free zone , Static area , Dynamic region ;
according to c/c++ Different object lifecycles ,c/c++ There are three different memory regions in the memory model of , Namely : Free storage , Dynamic region , Static area .
Free storage : Storage area of local non static variables , It's called the stack ;
Dynamic region : use new ,malloc Allocated memory , It's the usual pile ;
Static area : global variable , Static variable , Where string constants exist ;
notes : Code takes up memory , But not of c/c++ Part of the memory model ;

2020 More years , More complete , Update interview information of large factory , Welcome + Group learning and communication , Personal profile information plus group collection

Technology
©2019-2020 Toolsou All rights reserved,
C Language programming to find a student's grade java Realize the function of grabbing red packets Random forest R Language implementation QCustomPlot series (5)- Real time dynamic curve Software testing BUG describe use C++ I want to talk to you “ Prototype mode ” ( copy / copy constructor )JS How to operate China's longest high speed rail officially opened ! The fastest way to finish the race 30.5 hour Zimi apologizes :33W Gan charger delayed due to force majeure 2021 year 2 Chinese programming language ranking