Virtual address space of the process, stack, heap, data segment, code segment

 

The figure is a schematic diagram of the virtual address space of the process.

Stack segment:

  1 provide storage for local variables inside a function.

  2. When a function call, stored "Process Activity Log."

  3. as a temporary storage area. When computing a long arithmetic expression, you can be part of the calculation result onto the stack.

Data segment (static memory):

  BSS segment includes a data segment, the segment storage BSS uninitialized global variables, static variables. Data storage segment through global and static variable initialization.

Snippet:

  Also called text segment. Store instructions executable files.

stack:

  Like the stack segment can grow automatically as needed, the data segment is also a target for the completion of this work, this is the heap (heap). Heap area for storing dynamic allocation, i.e. a live memory malloc function. calloc and malloc and realloc similar. Before former returns a pointer to the allocated memory contents are cleared to zero. The latter change the size of a memory block pointer points, can expand and shrink, he often copied elsewhere memory then returns the new address.

 

1, the stack area (stack): allocated by the compiler automatically released, the stored function parameters, local variables, and the like. Operate similarly to a stack data structure. 

2, the heap area (heap): releasing assigned by the programmer, if the programmer does not release at the end of the program may be recovered by the OS. Note that it is a stack data structure totally different, it touches similar distribution list. 

 

3, the overall area (static region): global variables and static variables are stored in one and the other an initialized global and static variables in an area, uninitialized global variables and static variables uninitialized adjacent region. After the end of the program released by the system. 

4, literals area: constant string is placed here. After the end of the program released by the system. 

 

 

 

5, the program code area: storing binary code function body.

 

 

 

 
    The BSS: the BSS (bss segment) generally refers to a procedure used to store global variables uninitialized memory area and a static variable. BSS is the English abbreviation Block Started by Symbol. BSS segment is a static memory allocation.
    Data segments: the data segment (data segment) generally refers to an area of ​​memory used to store program variables initialized global and static variables. Data segment is a static memory allocation.
   代码段:代码段(code segment/text segment)通常是指用来存放程序执行代码的一块内存区域。这部分区域的大小在程序运行前就已经确定,并且内存区域通常属于只读, 某些架构也允许代码段为可写,即允许修改程序。在代码段中,也有可能包含一些只读的常数变量,例如字符串常量等。
    堆(heap):堆是用于存放进程运行中被动态分配的内存段,它的大小并不固定,可动态扩张或缩减。当进程调用malloc等函数分配内存时,新分配的内存就被动态添加到堆上(堆被扩张);当利用free等函数释放内存时,被释放的内存从堆中被剔除(堆被缩减)
    栈(stack):栈又称堆栈, 是用户存放程序临时创建的局部变量,也就是说我们函数括弧“{}”中定义的变量(但不包括static声明的变量,static意味着在数据段中存放变量)。除此以外,在函数被调用时,其参数也会被压入发起调用的进程栈中,并且待到调用结束后,函数的返回值也会被存放回栈中。由于栈的先进先出特点,所以栈特别方便用来保存/恢复调用现场。从这个意义上讲,我们可以把堆栈看成一个寄存、交换临时数据的内存区。堆栈又称堆栈(stack)在计算机科学中,是一种特殊的链表形式的数据结构,它的特殊之处在于只能允许在链表的一端(称为栈顶,英文为top)进行添加和删除操作。另外堆栈数据结构的实现也可以通过数组来完成。
    严格来说堆是指Heap,程序运行时供程序员来支配的一段内存。而栈Stack,多指函数调用时候参数的相互传递存在的内存区域。由于堆栈数据结构只允许在一端进行操作,因而按照先进后出(LIFO-Last In First Out)的原理工作。堆栈数据结构支持两种基本操作:压栈(push)和弹栈(pop):
   1. 压栈(入栈):将对象或者数据压入栈中,更新栈顶指针,使其指向最后入栈的对象或数据。
   2. 弹栈(出栈):返回栈顶指向的对象或数据,并从栈中删除该对象或数据,更新栈顶。

 

Guess you like

Origin www.cnblogs.com/senior-engineer/p/10963055.html