About Program Memory
When you run a program, your operating system loads the program into memory and defines an address space in which the program can operate. For example, if your program is executing in a 32-bit computer, the address space is approximately 4 gigabytes.
NOTE: This discussion is generally relevant to most computer architectures. For information specific to your system, check your vendor documentation.
An operating system does not actually allocate the memory in this address space. Instead, operating systems memory map this space, which means that the operating system relates the theoretical address space your program could use with what it actually will be using. Typically, operating systems divide memory into pages. When a program begins executing, the operating system creates a map that correlates the executing program with the pages that contain the program’s information. Figure 157 shows regions of a program with arrows pointing to the memory pages that contain different portions of your program, as well as a stack containing three stack frames, each mapped to its own page.
 
Figure 157, Mapping Program Pages
Similarly, the heap shows two allocations, each mapped to its own page. (This illustration vastly simplifies actual memory mapping, since a page can have many stack frames and many heap allocations.)
Figure 158 shows the compiling and linking dependencies for a program whose source code resides in four files.
Figure 158, Compiling Programs
Compiling these files creates object files, which a linker merges, along with any external libraries, into a load file. This load file is the executable program stored on your computer’s file system.
When the linker creates the load file, it combines the information contained in each of the object files into one unit. The load file at the bottom of Figure 158 also details this file’s contents, as this file contains a number of sections and additional information. For example:
*Data section—contains static variables and variables initialized outside of a function, for example:
 
int my_var1 = 10;
void main ()
{
static int my_var2 = 1;
int my_var3;
my_var3 = my_var1 + my_var2;
printf(“here’s what I’ve got: %i\n”, my_var3);
}
The data section contains the my_var1 and my_var2 variables. In contrast, the memory for the my_var3 variable is dynamically and automatically allocated and deallocated within the stack by your program’s runtime system.
*Symbol table section—contains addresses to the locations of routines and variables.
*Machine code section—contains an intermediate binary representation of your program. (It is intermediate because the linker has not yet resolved the addresses.)
*Header section—contains information about the size and location of information in all other sections of the object file.
The linker creates one file from all these sections that can be loaded into memory, Figure 159.
Figure 159, Linking a Program
TotalView can provide information about these sections and generate a leak detection report, Figure 160.
Figure 160, Memory Debugging Leak Report
For information, see Memory Leak Detection.