Data segments

Immediately above the text segment is the data segment, which is the place where the process holds the program's global and static variables (data).

Actually, it's not one mapping (segment); the data segment consists of three distinct mappings. In order from the low address, it consists of: the initialized data segment, the uninitialized data segment, and the heap segment.

We understand that, in a C program, uninitialized global and static variables are automatically initialized to zero. What about initialized globals? The initialized data segment is the region of address space where explicitly initialized global and static variables are stored.

The uninitialized data segment is the region of address space where, of course, uninitialized globals and static variables reside. The key point: these are implicitly initialized to zero (they're actually memset to zero). Also, older literature often refers to this region as the BSS. BSS is an old assembler directive – Block Started by Symbol – that can be ignored; today, the BSS region or segment is nothing but the uninitialized data segment of the process VAS.

The heap should be a term familiar to most C programmers; it refers to the memory region reserved for dynamic memory allocations (and subsequent free's). Think of the heap as a free gift of memory pages made available to the process at startup.

A key point: the text, initialized data, and uninitialized data segments are fixed in size; the heap is a dynamic segment – it can grow or shrink in size at runtime. It's important to note that the heap segment grows toward higher virtual addresses. Further details on the heap and its usage can be found in the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset