Expert C Programming

(Jeff_L) #1

block of this size, putting it right after the data segment. This block is zeroed out as it is put in the
program's address space. The entire stretch of data and BSS is usually just referred to jointly as the
data segment at this point. This is because a segment, in OS memory management terms, is simply a
range of consecutive virtual addresses, so adjacent segments are coalesced. The data segment is
typically the largest segment in any process.


The diagram shows the memory layout of a program that is about to begin execution. We still need
some memory space for local variables, temporaries, parameter passing in function calls, and the like.
A stack segment is allocated for this. We also need heap space for dynamically allocated memory.


This will be set up on demand, as soon as the first call to malloc() is made.


Note that the lowest part of the virtual address space is unmapped; that is, it is within the address
space of the process, but has not been assigned to a physical address, so any references to it will be
illegal. This is typically a few Kbytes of memory from address zero up. It catches references through
null pointers, and pointers that have small integer values.


When you take shared libraries into account, a process address space appears, as shown in Figure 6-3.


Figure 6-3. Virtual Address Space Layout, Showing Shared Libraries
Free download pdf