CISC 3595 — Operating System Spring, 2015 Chapter 3: Important Concepts (3/29/2015) 1 Memory from programmer’s perspective: you already know these:
- Code (functions) and data are loaded into memory when the program is being executed.
- Address of variables and functions (recall & operator): location of the variable/data and code in
memory: they are different for different run (concept of relocation: the same program can be loaded to different part of program and is able to run regardlessly.).
- A process’s address space (recall the figure) made up of text/code, data, heap, and stack
- segment. It is not necessarily a consecutive address space. (Note: you can use gdb, or just cout
statement in the code to examine the address of various variables, functions, ...).
- Variable’s lifetime can be static (located in data segment), automatic (located in stack), and
dynatmic (located in heap).
- stack and heap can grow, and there is an user setting that specify the maximum size of stack or
- heap. (You can use command ulimit -a to view your current settings).
- OS provides protection: typically a process cannot access a memory address within another
process’s address space. (Segmentation fault or bus error are generated when a process tries to access memory using an illegal address). 2 Memory from programmer’s perspective: there are more to know:
- One can create memory segment to be shared by multiple processes, in a way similar to the
case where mutliple threads share global variables. It’s up to the programmer to ensure mutual exclusion in order to avoid race condtion. (The system call to create shared memory segment is shmget in Unix.)
- Libraries: collections of commonly used functions and data, e.g., C++ standard library, STL
(Standard Template Library), POSIX thread library. Library’s code (functions’ implementation) can be linked to the progam in different ways: – static library is linked to the program’s code at compilation’s linking stage. This means a larger executable code, taking up more disk and memory space. (static library has a suffix of .a). – shared library: a stub function (instead of the actual function) is linked to the program’s code, which will binds to the actual function’s code (might be shared by multiple programs) when being called at run time. (Note: command ldd can be used to show the shared libraries that a program needs). Demo of lab5, see Makefile for details. – dynamically loaded: programmer can load and unload infrequently used library to save storage space, and to allow switching library implementation while the program’s running. (plugin behavior). 3 What we know about the memory, RAM, the hardware
- RAM stands for random access memory, meaning that you can access any random address of the
memory (in contrast, magnetic tape is a sequential access media, you need to wind (forward or backword) the tape to a location in order to access a certain part of the tape).
- The size of RAM is usually given in byte. RAM can be viewed as an array of bytes, with each
byte’s index being its address.