Storage Management
Storage Management
5.4. STORAGE MANAGEMENT
Different features in a language causes different
storage management techniques to be used.
J ?ORTRAN: no recursive calls, no dynamic storage
management.
J Pascal: stack-based storage management.
J LISP: garbage collection.
Language implementers decide about the details.
Programmers don·t know about it.
0
MAJOR RUN-TIME ELEMENTS REQUIRING
STORAGE
Data
operations
^
DATA AND PROGRAM REQUIRING STORAGE
Code segments for translated user programs.
System run-time programs.
J Supporting user programs.
J Like library routines, software interpreters or
translator, storage management routines.
User-defined data structures and constants.
Subprogram return points.
R
Referencing environments.
J Identifier associations (LISP A-list)
Temporaries in expression evaluation.
J Recursive function calls make it a lot.
Temporaries in parameter transmission.
J Resulting values for evaluation of actual parameters
are stored in temporaries until the total evaluation is
completed.
@
Input-output buffers.
J 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.
J System data like tables, status information for input-
output, ...
Ñ
MAJOR OPERATIONS REQUIRING STORAGE
Subprogram call and return operations.
J Activation record,
J local referencing environment, «
ÿ
PROGRAMMER- AND SYSTEM-
CONTROLLED STORAGE MANAGEMENT
Programmer control of storage management
J place a large and often undesirable burden on the
programmer,
J may interfere with the necessary system-controlled
storage management.
Programmer can cause dangling references and
garbage.
èhat language?
J Protection for the programmer by using a language
with strong typing and effective storage management
features,
J decrease in performance
OR
J performance
J more risk in having errors and fail during execution.
D
STORAGE MANAGEMENT PHASES
Initial allocation
Recovery
r
STATIC STORAGE MANAGEMENT
Simplest
static allocation
efficient
rr
In ?ORTRAN
J each subprogram is compiled separately,
J the code segment includes an activation record
compiled program,
its data areas,
r0
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.
r^
HEAP STORAGE MANAGEMENT: ?IXED-
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.
?ixed size elements allocated => no need for
compaction.
rR
RECOVERY
The problem: identification of reusable element,
solutions:
Explicit return by programmer or system.
J Natural, but cause garbage and dangling reference.
P.226
Reference counts.
J Cost of maintaining. P.227
J popular with parallel processing systems.
Garbage collection.
r@
GARBAGE COLLECTION
Dangling references more dangorous
Two stages
J Mark
garbage collection bit, set off if it is active.
J Sweep
links the ´onµ elements to the free list.
èhen is a heap element active?
There is a pointer to it from
outside the heap
rÑ
Three critical assumptions
J any active element must be reachable by a chain of
pointers beginning outside the heap.
J It must be possible to identify every pointer outside
the heap that points to an element inside the heap.
J It must be possible to identify within any active heap
element the fields that contain pointers to other heap
elements.
P. 231
rÿ
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.
r
Initial allocation and reuse.
reuse directly from a free-space list.
J ?irst-fit method
J best-fit method
keeping free-space list in size order.
Recovery with variable-size blocks.
J In first word of each block: a length indicator.
Compaction and memory fragmentation problem.
rD
Compaction approaches:
J Partial compaction
only adjacent free blocks
J ?ull compaction
active blocks may be shifted
0
!
!!"!
! ! !!
#!$ ! !!
%
m
%
§
§
m
m
M
M
M
M
m
m m &
#
6
#
m'
#
§!
!
"
!
HEAP COMPACTION
HEAP COMPACTION