Download - Storage Management
![Page 1: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/1.jpg)
COMPARATIVE STUDY OF PROGRAMMING LANGUAGES
STORAGE MANAGEMENT
Lecture 8 continued
![Page 2: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/2.jpg)
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
![Page 3: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/3.jpg)
MAJOR RUN-TIME ELEMENTS REQUIRING STORAGE
Data operations
3
![Page 4: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/4.jpg)
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
![Page 5: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/5.jpg)
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
![Page 6: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/6.jpg)
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
![Page 7: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/7.jpg)
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
![Page 8: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/8.jpg)
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
![Page 9: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/9.jpg)
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
![Page 10: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/10.jpg)
STORAGE MANAGEMENT PHASES
Initial allocation Recovery Compaction and reuse
10
![Page 11: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/11.jpg)
STATIC STORAGE MANAGEMENT
Simplest static allocation no run-time storage management no concern for recovery and reuse efficient in COBOL and FORTRAN
11
![Page 12: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/12.jpg)
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
![Page 13: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/13.jpg)
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
![Page 14: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/14.jpg)
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
![Page 15: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/15.jpg)
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
![Page 16: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/16.jpg)
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
![Page 17: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/17.jpg)
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
![Page 18: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/18.jpg)
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
![Page 19: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/19.jpg)
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
![Page 20: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/20.jpg)
Compaction approaches: Partial compaction
only adjacent free blocks Full compaction
active blocks may be shifted
20
![Page 21: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/21.jpg)
STORAGE MANAGEMENT Elements requiring storage
Programmer and system controlled storage
Static Storage Management
Heap Storage Management
![Page 22: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/22.jpg)
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
![Page 23: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/23.jpg)
ELEMENTS REQUIRING STORAGE
Temporaries in expression evaluation
Temporaries in parameter transmission
Input-Output buffers
Miscellaneous system data - tables etc
![Page 24: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/24.jpg)
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
![Page 25: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/25.jpg)
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
![Page 26: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/26.jpg)
STATIC STORAGE MANAGEMENT
Static allocation :
allocation during translation that
remains fixed throughout
execution.
Does not allow recursive
subprograms
![Page 27: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/27.jpg)
DYNAMIC ALLOCATION:HEAP STORAGE MANAGEMENT
Memory used for dynamic allocation of data objects in somewhat unstructured manner is called heap storage.
OS
HEAP
STACK
![Page 28: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/28.jpg)
HEAP STORAGE MANAGEMENT
Tasks: allocation, recovery,
dangling referencesgarbage collection
compaction, reuse
Fixed size elementsVariable size elements
![Page 29: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/29.jpg)
HEAP COMPACTION
used used used
used
used used
used
![Page 30: Storage Management](https://reader033.vdocument.in/reader033/viewer/2022061123/5475a012b4af9ff6628b45fd/html5/thumbnails/30.jpg)
HEAP COMPACTION
used used used
used
used usedused