All along, the memory model and Java memory model structure in C + + is a big problem that bothers me, which is also often tested in the interview. After a long period of excellence in learning, finally get the following Final Solution:)
C + + memory is divided into 5 regions ( stack full generation ):
1 Heap :
The memory block allocated by new, which releases the compiler from the tube, is controlled by our program itself (a new corresponds to a delete). If the programmer is not released, the OS is automatically recycled at the end of the program. Issues covered: "Buffer Overflow", "Memory Leak"
2. Stack stack:
Are those that the compiler allocates when needed, and automatically clears the store when it is not needed. Store local variables, function parameters.
The data stored in the stack is only valid in the current function and the next layer of functions, and once the function returns, the data is automatically freed.
3. Global/Static storage (. BSS segment and. Data segment):
Global and static variables are assigned to the same piece of memory. In the C language, uninitialized is placed in the. BSS segment, initialized in the. Data segment, and in C + + is not differentiated.
4. Constant Storage area (. Rodata segment):
Store constants and do not allow modification (can be modified by improper means)
5. Code Area (. Text segment):
Store code (such as a function), not allowed to modify (like a constant store), but can be executed (unlike a constant store)
Reference documents:
1. < system programmer Growth Plan > p22~
2. C + + heap, stack, global/static storage, constant storage http://www.cnitblog.com/guopingleee/archive/2009/02/16/54601.html
3. < programmer self-cultivation > p61~ 3.3 mining simplesection.o, but here is the introduction of the ELF format target file structure (that is, the file on disk storage structure), and "in-memory structure" or there is a difference, pay attention to distinguish
Memory model in C + +