Memory management

Definition

"Memory management is the act of managing computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when no longer needed. This is critical to any advanced computer system where more than a single process might be underway at any time."[from Wikipedia entry accessed 04-Nov-2014]

Explanation

All memory is limited. And so, like any limited resource it needs to be managed. This is the task of the memory manager which is part of the operating system. The CPU cannot access permanent storage so if a program needs to be run (i.e. become a process) it must be loaded into RAM.

The memory manager needs to allocate memory to programs and processes that demand to be run at the same time. Each program will be allocated a segment of memory so that the program code can be loaded into memory and space can be made available to store the data the program uses.

These processes and applications need to be protected from one another so that they do not overwrite each other.

A memory manager should not allow one program to affect the running of another program. i.e. it keeps each process entirely separate so that the operating system can load and unload applications without any problem. This is data security.

The memory manager should allow many applications to run at the same time. It must keep a memory allocation table so when the CPU switches between programs the right areas of memory are accessed. Some programs may also share the same data and therefore the memory manager has to allow this sharing.

[adapted from http://www.teach-ict.com/as_as_computing/ocr/H447/F453/3_3_1/memory%20management/miniweb/pg3.htm#]

Questions

Why does a program need to be loaded into memory before the instructions can be executed?

Why does an operating system need to manage memory?