Memory (Part 1)

 

When you tell your operating system to run a program, it loads the program and defines the address space that the program can access. For example, if your program is executing within a 32-bit computer, the address space is approximately 4 gigabytes.

The operating system does not actually allocate the memory in this address space. Instead, this space is memory mapped, which means the operating system maps the relationship between the theoretical address space and what it actually uses. In this way, your program only uses what it needs. Typically, operating systems divide memory into pages, and then create a map correlating the executing program with the pages that contain the program's information. The following illustration shows regions of a program. The arrows point to the memory pages containing the program's data:

In this figure, the stack contains three stack frames and each is mapped to its own page in this example. Similarly, the heap shows two allocations, each of which is mapped to its own page. (This isn't what really happens as a page can have many stack frames and many heap allocations. But doing this makes a nice picture.)


You can find tips that we've already sent out in our Tip Archive

Help us improve these tips!