A '''data segment''' is one of the sections of a program in an [[object file]] or in memory, which contains the [[global variable]]s that are initialized by the [[programmer]]. It has a fixed size, since all of the data in this section is set by the programmer before the program is loaded. However, it is not [[read-only]], since the values of the variables can be altered at [[runtime]]. This is in contrast to the [[Rodata]] (constant, read-only data) section, as well as the [[textcode segment]] (also known as text segment).
There are four basic memory regions program: Stack, Data, BSS, and Heap.
Sometimes the Datadata, BSS, and Heapheap areas are collectively referred to as the "data segment".
1. #The Data part contains constants used by the program that are not initialized to zero. For instance the string defined by <code>char s[] = "hello world";</code> would exist in the Datadata part.
#The [[.bss|BSS segment]] starts at the end of the data segment and contains all global variables that are initialized to zero. For instance a variable declared <code>static int i;</code> would be contained in the BSS segment.
2. #The BSS[[heap segmentarea]] startsbegins at the end of the Datadata segment and containsgrows allto globallarger variablesaddresses thatfrom arethere. initializedThe Heap area is managed by malloc, realloc, and free, which use the brk and sbrk system calls to zeroadjust its size. ForThe instanceHeap aarea variableis declaredshared staticby intall i;shared wouldlibraries beand containeddynamic inload themodules BSSin segmenta process.
The Data and BSS segments are fixed in size at link time and do not grow or change during program execution.
3. The Heap area begins at the end of the Data segment and grows to larger addresses from there. The Heap area is managed by malloc, realloc, and free, which use the brk and sbrk system calls to adjust its size. The Heap area is shared by all shared libraries and dynamic load modules in a process.
==See also==
|