Wednesday, January 12, 2011

Memory Management

Understanding Memory - From University of Alberta
Virtual memory is an abstraction layer that the operating system uses to insulate the memory hardware.

Executing a program interactively at the shell's command prompt is a common way to create a new process. The new process is literally spawned, or forked, from the shell process. In this way, a process hierarchy is established, with the shell as parent and the new process as child.

Programs comprise executable statements and data declarations. Each datum has a property known as storage class that reflects its lifespan during program execution. A related property called scope characterizes the extent of a datum's visibility. Storage class and scope are assumed from the location of a datum's declaration, and determine its placement within virtual memory.

Compilers translate a program's executable statements into CPU instructions, and declarations of static data are translated into machine-specific data specifications. To create an executable file, the system linker aggregates the instructions and the data into distinct segments. All of the instructions go into one segment traditionally called text. Meanwhile, the data are arranged into two segments. One is called data, for the initialized static data and literal constants, and the other, bss, for the uninitialized static data.

When the ELF file is executed, the text and the two data segments are loaded into separate areas of virtual memory.

Instead of mapping individual bytes, the page table maps larger chunks of virtual memory called pages. The corresponding increment of real memory is called a page frame. Page size is architecture-specific and often configurable. It is always some power of two.

Linking a static library into a program integrates the library's text and data segments into the ELF program file.

No comments: