storage management

Post on 26-Nov-2014

736 Views

Category:

Documents

7 Downloads

Preview:

Click to see full reader

TRANSCRIPT

COMPARATIVE STUDY OF PROGRAMMING LANGUAGES

STORAGE MANAGEMENT

Lecture 8 continued

5.4. STORAGE MANAGEMENT

Different features in a language causes different storage management techniques to be used. FORTRAN: no recursive calls, no dynamic storage

management. Pascal: stack-based storage management. LISP: garbage collection. Language implementers decide about the details. Programmers don’t know about it.

2

MAJOR RUN-TIME ELEMENTS REQUIRING STORAGE

Data operations

3

DATA AND PROGRAM REQUIRING STORAGE

Code segments for translated user programs. System run-time programs.

Supporting user programs. Like library routines, software interpreters or

translator, storage management routines. User-defined data structures and constants. Subprogram return points.

4

Referencing environments. Identifier associations (LISP A-list)

Temporaries in expression evaluation. Recursive function calls make it a lot.

Temporaries in parameter transmission. Resulting values for evaluation of actual

parameters are stored in temporaries until the total evaluation is completed.

5

Input-output buffers. Temporary storage areas used between the time

of the actual physical transfer of the data to or from external storage and the program-initiated input / output operation.

Miscellaneous system data. System data like tables, status information for

input-output, ...

6

MAJOR OPERATIONS REQUIRING STORAGE

Subprogram call and return operations. Activation record, local referencing environment, …

Data structure creation and destruction operations. new - dispose in Pascal. malloc - free in C

Component insertion and deletion operations. ML and Lisp list operations, inserting a

component into a list.7

PROGRAMMER- AND SYSTEM- CONTROLLED STORAGE MANAGEMENT

Programmer control of storage management place a large and often undesirable burden on

the programmer, may interfere with the necessary system-

controlled storage management. Programmer can cause dangling references

and garbage.

8

What language? Protection for the programmer by using a

language with strong typing and effective storage management features,

decrease in performanceOR performance more risk in having errors and fail during

execution.

9

STORAGE MANAGEMENT PHASES

Initial allocation Recovery Compaction and reuse

10

STATIC STORAGE MANAGEMENT

Simplest static allocation no run-time storage management no concern for recovery and reuse efficient in COBOL and FORTRAN

11

In FORTRAN each subprogram is compiled separately, the code segment includes an activation record

compiled program, its data areas, return point location, miscellaneous items of system data.

12

STACK-BASED STORAGE MANAGEMENT

Simplest run-time storage management technique.

Based on the nested last in first out structure in subprograms calls and returns.

Automatic compaction. In Pascal : a single central stack of activation

records, and a statically allocated area for subprogram code segments and system programs.

P.222, fig. 5.5

13

HEAP STORAGE MANAGEMENT: FIXED-SIZE ELEMENTS

A heap is a block of storage within which pieces are allocated and freed in some relatively unstructured manner.

Need for heap , when a language permits storage to be allocated and freed at execution time.

Fixed size elements allocated => no need for compaction.

14

RECOVERY

The problem: identification of reusable element, solutions:

Explicit return by programmer or system. Natural, but cause garbage and dangling

reference. P.226 Reference counts.

Cost of maintaining. P.227 popular with parallel processing systems.

Garbage collection.

15

GARBAGE COLLECTION Dangling references more dangorous Two stages

Mark garbage collection bit, set off if it is active.

Sweep links the “on” elements to the free list.

When is a heap element active? There is a pointer to it from

outside the heap another active heap element

16

Three critical assumptions any active element must be reachable by a chain

of pointers beginning outside the heap. It must be possible to identify every pointer

outside the heap that points to an element inside the heap.

It must be possible to identify within any active heap element the fields that contain pointers to other heap elements.

P. 231

17

HEAP STORAGE MANAGEMENT:VARIABLE-SIZE ELEMENTS

More difficult if space for programmer defined data

structures is sequential, like arrays or activation records.

Major difficulty : reuse of recovered space.

18

Initial allocation and reuse. reuse directly from a free-space list.

First-fit method best-fit methodkeeping free-space list in size order.

Recovery with variable-size blocks. In first word of each block: a length indicator.

Compaction and memory fragmentation problem.

19

Compaction approaches: Partial compaction

only adjacent free blocks Full compaction

active blocks may be shifted

20

STORAGE MANAGEMENT Elements requiring storage

Programmer and system controlled storage

Static Storage Management

Heap Storage Management

ELEMENTS REQUIRING STORAGE

Code segments for translated user programs

System run-time programs - e.g. libraries

User defined data structures and constants

Subprogram return points

Referencing environments

ELEMENTS REQUIRING STORAGE

Temporaries in expression evaluation

Temporaries in parameter transmission

Input-Output buffers

Miscellaneous system data - tables etc

OPERATIONS THAT REQUIRE STORAGE ALLOCATION

Subprogram call and return operations - creation and deletion of activation records

Explicit data structure creation and destruction operations

Component insertion and deletion operations

PROGRAMMER AND SYSTEM CONTROLLED STORAGE

Pros and cons:Programmer knows when to allocate / free storage.

Programmer may interfere with the system-controlled storage management

Storage-Management PhasesInitial allocationRecoveryCompaction and reuse

STATIC STORAGE MANAGEMENT

Static allocation :

allocation during translation that

remains fixed throughout

execution.

Does not allow recursive

subprograms

DYNAMIC ALLOCATION:HEAP STORAGE MANAGEMENT

Memory used for dynamic allocation of data objects in somewhat unstructured manner is called heap storage.

OS

HEAP

STACK

HEAP STORAGE MANAGEMENT

Tasks: allocation, recovery,

dangling referencesgarbage collection

compaction, reuse

Fixed size elementsVariable size elements

HEAP COMPACTION

used used used

used

used used

used

HEAP COMPACTION

used used used

used

used usedused

top related