memory management. memory commemoration or remembrance

21
Memory Management

Upload: malcolm-dixon

Post on 04-Jan-2016

224 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Memory Management. Memory  Commemoration or Remembrance

Memory Management

Page 2: Memory Management. Memory  Commemoration or Remembrance

Memory

Commemoration or Remembrance

Page 3: Memory Management. Memory  Commemoration or Remembrance

Management

the technique, practice or science of managing.

Page 4: Memory Management. Memory  Commemoration or Remembrance

Memory Management Commemoration Technique

Page 5: Memory Management. Memory  Commemoration or Remembrance

The Memory Management

Memory management is a complex field of computer science and there are many techniques being developed to make it more efficient. This guide is designed to introduce you to some of the basic memory management issues that programmers face.

Page 6: Memory Management. Memory  Commemoration or Remembrance

Memory managementis usually divided into three areas: Hardware, Operating System, and application, although the distinctions are a little fuzzy. In most computer systems, all three are present to some extent, forming layers between the user's program and the actual memory hardware. The Memory Management Reference is mostly concerned with application memory management.

Page 7: Memory Management. Memory  Commemoration or Remembrance

Hardware memory management

Memory management at the hardware level is concerned with the electronic devices that actually store data. This includes things like RAM and memory caches.

Page 8: Memory Management. Memory  Commemoration or Remembrance

Operating system memory managementIn the operating system, memory must be allocated to user programs, and reused by other programs when it is no longer required. The operating system can pretend that the computer has more memory than it actually does, and also that each program has the machine's memory to itself; both of these are features of virtual memory systems.

Page 9: Memory Management. Memory  Commemoration or Remembrance

Application memory management

Application memory management involves supplying the memory needed for a program's objects and data structures from the limited resources available, and recycling that memory for reuse when it is no longer required. Because application programs cannot in general predict in advance how much memory they are going to require, they need additional code to handle their changing memory requirements.

Page 10: Memory Management. Memory  Commemoration or Remembrance

Application memory management combines two related tasks

AllocationWhen the program requests a block

of memory, the memory manager must allocate that block out of the larger blocks it has received from the operating system. The part of the memory manager that does this is known as the allocator.

Page 11: Memory Management. Memory  Commemoration or Remembrance

RecyclingWhen memory blocks have been allocated,

but the data they contain is no longer required by the program, then the blocks can be recycled for reuse. There are two approaches to recycling memory: either the programmer must decide when memory can be reused (known as manual memory management); or the memory manager must be able to work it out (known as automatic memory management). These are both described in more detail below.

Page 12: Memory Management. Memory  Commemoration or Remembrance

CPU overheadThe additional time taken by the memory

manager while the program is running;Interactive pause times

How much delay an interactive user observes;Memory overhead

How much space is wasted for administration, rounding (known as internal fragmentation), and poor layout (known as external fragmentation).

Page 13: Memory Management. Memory  Commemoration or Remembrance

Memory management problems

Memory management problemsThe basic problem in managing

memory is knowing when to keep the data it contains, and when to throw it away so that the memory can be reused.

Page 14: Memory Management. Memory  Commemoration or Remembrance

Premature free or dangling pointerMany programs give up memory,

but attempt to access it later and crash or behave randomly. Memory leak

Some programs continually allocate memory without ever giving it up and eventually run out of memory. This condition is known as a memory leak.

Page 15: Memory Management. Memory  Commemoration or Remembrance

External fragmentationA poor allocator can do its job of

giving out and receiving blocks of memory so badly that it can no longer give out big enough blocks despite having enough spare memory.

Page 16: Memory Management. Memory  Commemoration or Remembrance

Poor locality of referenceAnother problem with the layout of

allocated blocks comes from the way that modern hardware and operating system memory managers handle memory: successive memory accesses are faster if they are to nearby memory locations.

Page 17: Memory Management. Memory  Commemoration or Remembrance

Inflexible design These problems occur because any

memory management solution tends to make assumptions about the way in which the program is going to use memory, such as typical block sizes, reference patterns, or lifetimes of objects.

Page 18: Memory Management. Memory  Commemoration or Remembrance

Interface complexityIf objects are passed between

modules, then the interface design must consider the management of their memory.

Page 19: Memory Management. Memory  Commemoration or Remembrance

Automatic memory management

Automatic memory management is a service, either as a part of the language or as an extension, that automatically recycles memory that a program would not otherwise use again.

Page 20: Memory Management. Memory  Commemoration or Remembrance

The advantages of automatic memory management are:

The programmer is freed to work on the actual problem;

Module interfaces are cleaner; There are fewer memory management

bugs; Memory management is often more

efficient.

Page 21: Memory Management. Memory  Commemoration or Remembrance

The disadvantages of automatic memory management are:

Memory may be retained because it is reachable, but won't be used again;

Automatic memory managers (currently) have limited availability.