Data segment
"data segment段=bss段+initialized data segment段"
wikipedia Data segment
In computing, a data segment (often denoted .data) is a portion of an object file or the corresponding address space of a program that contains initialized static variables, that is, global variables and static local variables. The size of this segment is determined by the size of the values in the program's source code, and does not change at run time.
NOTE: 在一些其他的文章中,也使用了 data segment 这个词,在其中的一些内容初读起来是会和上面的最后一句话 "and does not change at run time " 相矛盾的,在下面章节中,罗列了这些文章,这些文章主要是Linux OS相关的,其实它们是并不矛盾的,这些文章的内容涉及到了底层的实现细节,当深入这些实现细节后,会发现它们其实是并不矛盾的。
Use case
下面这些文章中,也使用了data segment这个词语,初读起来,是和 wikipedia Data segment 中的 "The size of this segment is determined by the size of the values in the program's source code, and does not change at run time " 相矛盾的,参看 Kernel\Guide\Multitasking\Process-model\Process-resource\Process-memory-model\Linux-implementation
章节学习实现细节后,从实现角度来看,它们是并不矛盾的。
wikipedia C dynamic memory allocation # Implementations # Heap-based
Implementation of the allocator is commonly done using the heap, or data segment. The allocator will usually expand and contract the heap to fulfill allocation requests.
wikipedia sbrk
brk and sbrk are basic memory management system calls used in Unix and Unix-like operating systems to control the amount of memory allocated to the data segment of the process.[1]
NOTE: 上面这段话中,说明了在Linux OS中的implementation中会改变 the data segment of the process。
man7 brk(2) — Linux manual page
brk()
and sbrk()
change the location of the program break, which defines the end of the process's data segment (i.e., the program break is the first location after the end of the uninitialized data segment).