SlideShare a Scribd company logo
Run-Time Environment
Lecture 15
Run time Addressing
• Given a variable reference in the code, how
can we find the correct instance of that
variable?
• Things are trickier – variables can live on the
stack.
• Tied to issues of scope
Storage and access for locally declared data
• The executing procedure uses the frame pointer to
quickly access values in its stack frame as the
frame pointer points to the start of the frame.
• Then add the variable’s offset from the start of the
frame. Calculating local data’s offset (to be stored
in the symbol table)
• However problem arise for variable length data
• Goal:
Allow a routine to have variable-length data
(i.e., dynamically-sized arrays) as local data in frame
• Option 1:
Allocate the variable on the heap
Work with pointers to the data
Auto free the data when the routine returns
• Option 2:
Create the variable on the stack, dynamically
Effectively: Enlarge the frame as necessary
Still need to work with pointers
Variable-Length Local Variables
Variable Length Data
return value
actual parameters
optional control link
optional access link
saved machine
status
local data
pointer a
pointer b
temporaries
array a
array b
Control link and saved status
Control link and saved status
………
Pointer to a
Pointer to b
….
Array a
Array b
Activationrecord
forp
Activation
record
forq
Arrays
ofp
Arrays
ofq
top
Variable length data is allocated after
temporaries, and there is a link to from
local data to that array.
top_sp
Variable-Length Local Variables
Local Variables at fixed offsets from
FP
Dynamically sized variables use
hidden pointers
All references to “a” and “b” will be
indirect through hidden pointers
Frame
Data Access Without Nested Procedures
• Does not allow nested procedure declaration
– Variables are either local or global
• Allocation and access to variables are simple
– Global variables
• Allocated static storage
• Locations remain fixed and known at compile time
• Access possible using statically determined address
– Local variables may be accesses using top_sp
pointer
Scope
The scope of a variable is that portion of the programs
to which the variable applies.
• A variable islocal to a procedure if the declaration
occurs in that procedure.
• A variable is non-local to a procedure if it is not local
to that procedure but the declaration occurs in an
enclosing scope of that procedure.
• A variable is global if it occurs in the outermost
scope.
Types of Scoping
• Static – scope of a variable determined from the
source code. Scope A is enclosed in scope B if
A's source code is nested inside B's source
code.
• Dynamic – current call tree determines the
relevant declaration of a variable use.
Static Scoping Rules
Dynamic Scoping Rules
Local / Non-Local Variables
Local / Non-Local Variables
Local / Non-Local Variables
Local / Non-Local Variables
The Static Link
The Static Link
The Static Link
Given a variable usage...
How do we find the frame containing the right
variable?
Assume that x is declared at lexical level M.
Assume that x is used at lexical level N.
(We must have N  M)
At runtime...
Follow N-M static links to find the right frame.
Use the offset of x within that frame.
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2
Initializing the Static Link
Initializing the Static Link
• At runtime, we can’t know where the relevant
activation record holding the variable exists on the
stack
• Use static (access) links to enable quick location
– addr(x) = # static links + x's offset
– Local: (0,offset)
– Immediately enclosing scope: (1,offset)
Runtime Addressing in Stack Allocation
Display Registers
To access a non-local variable
How to Maintain the Display Registers?
How to Maintain the Display Registers?
How to Maintain the Display Registers?
How to Maintain the Display Registers?
How to Maintain the Display Registers?
How to Maintain the Display Registers?
How to Maintain the Display Registers?
How to Maintain the Display Registers?
Various approaches to passing data into and out of a
procedure via parameters
1. Call-by-value – data is copied at the callee into
activation and any item changes do not affect
values in the caller.
• Ex: C parameters
2. Call-by-reference – pointer to data is placed in the
callee activation and any changes made by the
callee are indirect references to the actual value in
the caller.
• C++ - call-by-value and call-by-reference
Parameter Passing
var a,b : integer
procedure swap(x,y : integer);
var t: integer;
begin t := x; x := y; y := t; end;
begin
a := 1;b := 2;
swap(a,b);
write ('a = ',a);
write ('b = ',b);
end.
value reference
write(a) 1 2
write(b) 2 1
Call-by-value vs Call-by-reference
3. Call-by-value-result (copy-restore) – hybrid of
call-by-value and call-by-reference. Data
copied at the callee. During the call, changes do
not affect the actual parameter. After the call,
the actual value is updated.
4. Call-by-name – the actual parameter is in-line
substituted into the called procedure. This
means it is not evaluated until it is used.
Parameter Passing
var a: integer
procedure foo(x: integer);
begin a := a + 1; x := x + 1; end;
begin
a := 1;
foo(a);
write ('a = ',a);
end.
Value-result reference
write(a) 2 3
Call-by-value-result vs. Call-by-reference
var a : array of integer; i: integer
procedure swap(x,y : integer);
var t: integer;
begin t := x; x := y; y := t; end;
begin
i := 1;
swap(i,a[i]);
write (‘i,a[i] = ’,i,a[i]);
end.
Call-by-name vs. Call-by-reference
Heap
• Heap is used for data that lives indefinitely or until
the program explicitly deletes it
• Local variables become inaccessible when
their procedures end
• Many language enable us to create objects or
other data whose existence is not tied to their
procedure activations
– In C++/Java we can create objects using new
keyword and may be passed to other procedures
Heap Management
• Memory Manager
– Allocates and deallocates space within the heap.
– Serves as an interface between application programs
and operating system
– For some languages that need to deallocate space
manually MM is responsible for implementing that.
• Garbage Collector
– Responsible for finding spaces within the heap that are
no longer used by the program and the deallocate them
– GC is an important subsystem of the memory manager
Memory Manager
• Keeps track of all the free space in heap storage at all
times.
• Two basic functions
– Allocation –
• In response to some request MM produces a chunk of
contiguous heap memory
• If not possible then seeks to increase heap storage from
virtual memory
– Deallocation –
• MM returns deallocated space to the pool of free space
Memory Manager
• MM would be simpler if
– All requests were for the same sized chunks
– Storage were released in first-allocated first-deallocated
style
• BUT!! None is possible in most languages
• MM should be prepared to
– Serve requests in any order
– Serve requests of any size
Properties of Memory Manager
• Desired properties of MM
– Space Efficiency
• Should minimize the total heap spaced needed
• Can be achieved by minimizing fragmentation
– Program Efficiency
• Should make good use of the memory to allow program
to run faster
• Should take advantage of ‘locality’ characteristics of
program
– Low Overhead
• Allocation and deallocation operations should be as
efficient as possible
Memory Hierarchy
• Registers are managed by the generated code
• All other levels are managed automatically
• With each memory access the machine searches each level of the
memory in succession starting from the lowest level
Virtual Memory (Disk)
Physical Memory
2nd-Level Cache
1st-Level Cache
Registers (Processor)
Typical Sizes
> 2 GB
256MB-2GB
128KB-4MB
16KB-64KB
32 Words
Typical Access Times
3-15 ms
100-150ns
40-60ns
5-10ns
1ns
Memory Hierarchy
• Data is transferred as blocks of contiguous storage
• Larger blocks are used with the slower levels of the
hierarchy
• Cache lines
– Data blocks transferred between main memory and
cache
– Typically from 32 to 256 byets
• Pages
– Data transferred between virtual memory and main
memory
– Typically between 4K and 64K
Fragmentation
• Variable-sized chunks of memory are
allocated.
• Some chunks are freed (in more-or-less
random order).
• The resulting free space become
“fragmented”.
• Need to allocate more space?
• Adequate space is available
... but it is not contiguous!
• Even if holes are larger than the request
…. We need to split the hole
…. Creating yet smaller hole
Holes
Fragmentation Reduction
• Control how the MM places new objects in the heap
• Best-Fit Algorithm
– Allocate the requested memory in the smallest
available hole that is large enough
– Spares larger holes for subsequent larger requests
– Good strategy for real-life programs
• First-Fit Algorithm
– Object is placed in the first hole in which it fits
– Takes less time to place objects
– Overall performance is inferior to best-fit
Managing Free Space
• Coalescing a recently feed chunk to the adjacent free
chunk forms larger chunk
– We can always use a larger chunk to do the work of
small chunks of equal total size
• For bins of one fixed size we don’t want to coalesce
– Simple to keep track of allocation/deallocation using bit
map
• 1 indicates allocated
• 0 indicates free
Problems with Manual Deallocation
• Two common mistakes
1. Memory Leak
• Failing ever to delete data that will never be referenced
• Slow down the program due to increased memory
usage
• Critical for long running/nonstop program such as OS or
server
• Does not affect program correctness
• Automatic garbage collection gets rid of it
– Even the program may use more memory than necessary
Problems with Manual Deallocation
• Two common mistakes
2. Dangling Pointer Reference
• Delete some storage and try to refer to the data
in the deallocated storage
• Once the freed storage is reallocated any read,
write or deallocation via dangling pointer can
produce random effects
• Dereferencing a dangling pointer creates program
error hard to debug

More Related Content

DOCX
Compiler Design Material
PPTX
Compiler Design
KEY
Unit 1 cd
PPT
Compiler Design Unit 1
PPSX
Spr ch-05-compilers
PDF
Compiler unit 1
PPTX
Programming the basic computer
PPT
Chapter Seven(1)
Compiler Design Material
Compiler Design
Unit 1 cd
Compiler Design Unit 1
Spr ch-05-compilers
Compiler unit 1
Programming the basic computer
Chapter Seven(1)

What's hot (20)

PPTX
Lecture 14 run time environment
PDF
Lecture 01 introduction to compiler
PPT
Chapter One
PPTX
Assemblers
PPTX
System Programing Unit 1
PPTX
Intermediate code- generation
PPTX
System Programming Unit III
PPT
Lec 04 intro assembly
PPTX
C basics
PPT
Lexical analyzer
PPT
Assembler Language Tutorial for Mainframe Programmers
PPTX
Workshop Assembler
PPT
Chap 1-language processor
PDF
Run time storage
PDF
P code
PDF
Introduction to compilers
PPSX
Compiler designs presentation final
PPT
Compiler Design Basics
PDF
08 subprograms
PDF
Compiler unit 4
Lecture 14 run time environment
Lecture 01 introduction to compiler
Chapter One
Assemblers
System Programing Unit 1
Intermediate code- generation
System Programming Unit III
Lec 04 intro assembly
C basics
Lexical analyzer
Assembler Language Tutorial for Mainframe Programmers
Workshop Assembler
Chap 1-language processor
Run time storage
P code
Introduction to compilers
Compiler designs presentation final
Compiler Design Basics
08 subprograms
Compiler unit 4
Ad

Similar to Lecture 15 run timeenvironment_2 (20)

PPTX
Activation Racords and Run-time Environments _11_10_2024.pptx
PPT
Runtimeenvironment
PPT
7. Key-Value Databases: In Depth
PPTX
Intro to Data Structure & Algorithms
PDF
Building Big Data Streaming Architectures
PPTX
.NET UY Meetup 7 - CLR Memory by Fabian Alves
PPTX
DSC650 : DATA TECHNOLOGY AND FUTURE EMERGENCE (CHAPTER 4)
PPTX
Interprocess Communication important topic in iOS .pptx
PPTX
Heap Memory Management.pptx
PPTX
The Case for a Signal Oriented Data Stream Management System
PDF
Hadoop Ecosystem and Low Latency Streaming Architecture
PDF
Cosmos DB at VLDB 2019
PDF
Architecting for the cloud elasticity security
PPTX
CPP19 - Revision
PPT
PPTX
Apache Big Data 2016: Next Gen Big Data Analytics with Apache Apex
PPT
U4-p2 Run TIme Environment SOurce language.ppt
PPT
U4-p2 Run Time Environment Source language.ppt
PDF
PPTX
General Programming Concept
Activation Racords and Run-time Environments _11_10_2024.pptx
Runtimeenvironment
7. Key-Value Databases: In Depth
Intro to Data Structure & Algorithms
Building Big Data Streaming Architectures
.NET UY Meetup 7 - CLR Memory by Fabian Alves
DSC650 : DATA TECHNOLOGY AND FUTURE EMERGENCE (CHAPTER 4)
Interprocess Communication important topic in iOS .pptx
Heap Memory Management.pptx
The Case for a Signal Oriented Data Stream Management System
Hadoop Ecosystem and Low Latency Streaming Architecture
Cosmos DB at VLDB 2019
Architecting for the cloud elasticity security
CPP19 - Revision
Apache Big Data 2016: Next Gen Big Data Analytics with Apache Apex
U4-p2 Run TIme Environment SOurce language.ppt
U4-p2 Run Time Environment Source language.ppt
General Programming Concept
Ad

More from Iffat Anjum (20)

PPTX
Fog computing ( foggy cloud)
PPTX
Cognitive radio network_MS_defense_presentation
PPT
Lecture 16 17 code-generation
PPTX
Lecture 12 intermediate code generation
PPT
Lecture 13 intermediate code generation 2.pptx
PPTX
Lecture 11 semantic analysis 2
PPTX
Lecture 09 syntax analysis 05
PPTX
Lecture 10 semantic analysis 01
PPTX
Lecture 07 08 syntax analysis-4
PPT
Lecture 06 syntax analysis 3
PPT
Lecture 05 syntax analysis 2
PPT
Lecture 03 lexical analysis
PPT
Lecture 04 syntax analysis
PPTX
Lecture 02 lexical analysis
PPT
Compiler Design - Introduction to Compiler
PPTX
Distributed contention based mac protocol for cognitive radio
PPT
On qo s provisioning in context aware wireless sensor networks for healthcare
PPT
Data link control
PPT
Pnp mac preemptive slot allocation and non preemptive transmission for provid...
PPT
Qo s based mac protocol for medical wireless body area sensor networks
Fog computing ( foggy cloud)
Cognitive radio network_MS_defense_presentation
Lecture 16 17 code-generation
Lecture 12 intermediate code generation
Lecture 13 intermediate code generation 2.pptx
Lecture 11 semantic analysis 2
Lecture 09 syntax analysis 05
Lecture 10 semantic analysis 01
Lecture 07 08 syntax analysis-4
Lecture 06 syntax analysis 3
Lecture 05 syntax analysis 2
Lecture 03 lexical analysis
Lecture 04 syntax analysis
Lecture 02 lexical analysis
Compiler Design - Introduction to Compiler
Distributed contention based mac protocol for cognitive radio
On qo s provisioning in context aware wireless sensor networks for healthcare
Data link control
Pnp mac preemptive slot allocation and non preemptive transmission for provid...
Qo s based mac protocol for medical wireless body area sensor networks

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Pharma ospi slides which help in ospi learning
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
master seminar digital applications in india
PDF
Complications of Minimal Access Surgery at WLH
STATICS OF THE RIGID BODIES Hibbelers.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPH.pptx obstetrics and gynecology in nursing
Pharma ospi slides which help in ospi learning
TR - Agricultural Crops Production NC III.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
2.FourierTransform-ShortQuestionswithAnswers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Abdominal Access Techniques with Prof. Dr. R K Mishra
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Computing-Curriculum for Schools in Ghana
Module 4: Burden of Disease Tutorial Slides S2 2025
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Final Presentation General Medicine 03-08-2024.pptx
Cell Types and Its function , kingdom of life
Microbial diseases, their pathogenesis and prophylaxis
master seminar digital applications in india
Complications of Minimal Access Surgery at WLH

Lecture 15 run timeenvironment_2

  • 2. Run time Addressing • Given a variable reference in the code, how can we find the correct instance of that variable? • Things are trickier – variables can live on the stack. • Tied to issues of scope
  • 3. Storage and access for locally declared data • The executing procedure uses the frame pointer to quickly access values in its stack frame as the frame pointer points to the start of the frame. • Then add the variable’s offset from the start of the frame. Calculating local data’s offset (to be stored in the symbol table) • However problem arise for variable length data
  • 4. • Goal: Allow a routine to have variable-length data (i.e., dynamically-sized arrays) as local data in frame • Option 1: Allocate the variable on the heap Work with pointers to the data Auto free the data when the routine returns • Option 2: Create the variable on the stack, dynamically Effectively: Enlarge the frame as necessary Still need to work with pointers Variable-Length Local Variables
  • 5. Variable Length Data return value actual parameters optional control link optional access link saved machine status local data pointer a pointer b temporaries array a array b Control link and saved status Control link and saved status ……… Pointer to a Pointer to b …. Array a Array b Activationrecord forp Activation record forq Arrays ofp Arrays ofq top Variable length data is allocated after temporaries, and there is a link to from local data to that array. top_sp
  • 6. Variable-Length Local Variables Local Variables at fixed offsets from FP Dynamically sized variables use hidden pointers All references to “a” and “b” will be indirect through hidden pointers Frame
  • 7. Data Access Without Nested Procedures • Does not allow nested procedure declaration – Variables are either local or global • Allocation and access to variables are simple – Global variables • Allocated static storage • Locations remain fixed and known at compile time • Access possible using statically determined address – Local variables may be accesses using top_sp pointer
  • 8. Scope The scope of a variable is that portion of the programs to which the variable applies. • A variable islocal to a procedure if the declaration occurs in that procedure. • A variable is non-local to a procedure if it is not local to that procedure but the declaration occurs in an enclosing scope of that procedure. • A variable is global if it occurs in the outermost scope.
  • 9. Types of Scoping • Static – scope of a variable determined from the source code. Scope A is enclosed in scope B if A's source code is nested inside B's source code. • Dynamic – current call tree determines the relevant declaration of a variable use.
  • 12. Local / Non-Local Variables
  • 13. Local / Non-Local Variables
  • 14. Local / Non-Local Variables
  • 15. Local / Non-Local Variables
  • 18. The Static Link Given a variable usage... How do we find the frame containing the right variable? Assume that x is declared at lexical level M. Assume that x is used at lexical level N. (We must have N  M) At runtime... Follow N-M static links to find the right frame. Use the offset of x within that frame.
  • 24. • At runtime, we can’t know where the relevant activation record holding the variable exists on the stack • Use static (access) links to enable quick location – addr(x) = # static links + x's offset – Local: (0,offset) – Immediately enclosing scope: (1,offset) Runtime Addressing in Stack Allocation
  • 26. To access a non-local variable
  • 27. How to Maintain the Display Registers?
  • 28. How to Maintain the Display Registers?
  • 29. How to Maintain the Display Registers?
  • 30. How to Maintain the Display Registers?
  • 31. How to Maintain the Display Registers?
  • 32. How to Maintain the Display Registers?
  • 33. How to Maintain the Display Registers?
  • 34. How to Maintain the Display Registers?
  • 35. Various approaches to passing data into and out of a procedure via parameters 1. Call-by-value – data is copied at the callee into activation and any item changes do not affect values in the caller. • Ex: C parameters 2. Call-by-reference – pointer to data is placed in the callee activation and any changes made by the callee are indirect references to the actual value in the caller. • C++ - call-by-value and call-by-reference Parameter Passing
  • 36. var a,b : integer procedure swap(x,y : integer); var t: integer; begin t := x; x := y; y := t; end; begin a := 1;b := 2; swap(a,b); write ('a = ',a); write ('b = ',b); end. value reference write(a) 1 2 write(b) 2 1 Call-by-value vs Call-by-reference
  • 37. 3. Call-by-value-result (copy-restore) – hybrid of call-by-value and call-by-reference. Data copied at the callee. During the call, changes do not affect the actual parameter. After the call, the actual value is updated. 4. Call-by-name – the actual parameter is in-line substituted into the called procedure. This means it is not evaluated until it is used. Parameter Passing
  • 38. var a: integer procedure foo(x: integer); begin a := a + 1; x := x + 1; end; begin a := 1; foo(a); write ('a = ',a); end. Value-result reference write(a) 2 3 Call-by-value-result vs. Call-by-reference
  • 39. var a : array of integer; i: integer procedure swap(x,y : integer); var t: integer; begin t := x; x := y; y := t; end; begin i := 1; swap(i,a[i]); write (‘i,a[i] = ’,i,a[i]); end. Call-by-name vs. Call-by-reference
  • 40. Heap • Heap is used for data that lives indefinitely or until the program explicitly deletes it • Local variables become inaccessible when their procedures end • Many language enable us to create objects or other data whose existence is not tied to their procedure activations – In C++/Java we can create objects using new keyword and may be passed to other procedures
  • 41. Heap Management • Memory Manager – Allocates and deallocates space within the heap. – Serves as an interface between application programs and operating system – For some languages that need to deallocate space manually MM is responsible for implementing that. • Garbage Collector – Responsible for finding spaces within the heap that are no longer used by the program and the deallocate them – GC is an important subsystem of the memory manager
  • 42. Memory Manager • Keeps track of all the free space in heap storage at all times. • Two basic functions – Allocation – • In response to some request MM produces a chunk of contiguous heap memory • If not possible then seeks to increase heap storage from virtual memory – Deallocation – • MM returns deallocated space to the pool of free space
  • 43. Memory Manager • MM would be simpler if – All requests were for the same sized chunks – Storage were released in first-allocated first-deallocated style • BUT!! None is possible in most languages • MM should be prepared to – Serve requests in any order – Serve requests of any size
  • 44. Properties of Memory Manager • Desired properties of MM – Space Efficiency • Should minimize the total heap spaced needed • Can be achieved by minimizing fragmentation – Program Efficiency • Should make good use of the memory to allow program to run faster • Should take advantage of ‘locality’ characteristics of program – Low Overhead • Allocation and deallocation operations should be as efficient as possible
  • 45. Memory Hierarchy • Registers are managed by the generated code • All other levels are managed automatically • With each memory access the machine searches each level of the memory in succession starting from the lowest level Virtual Memory (Disk) Physical Memory 2nd-Level Cache 1st-Level Cache Registers (Processor) Typical Sizes > 2 GB 256MB-2GB 128KB-4MB 16KB-64KB 32 Words Typical Access Times 3-15 ms 100-150ns 40-60ns 5-10ns 1ns
  • 46. Memory Hierarchy • Data is transferred as blocks of contiguous storage • Larger blocks are used with the slower levels of the hierarchy • Cache lines – Data blocks transferred between main memory and cache – Typically from 32 to 256 byets • Pages – Data transferred between virtual memory and main memory – Typically between 4K and 64K
  • 47. Fragmentation • Variable-sized chunks of memory are allocated. • Some chunks are freed (in more-or-less random order). • The resulting free space become “fragmented”. • Need to allocate more space? • Adequate space is available ... but it is not contiguous! • Even if holes are larger than the request …. We need to split the hole …. Creating yet smaller hole Holes
  • 48. Fragmentation Reduction • Control how the MM places new objects in the heap • Best-Fit Algorithm – Allocate the requested memory in the smallest available hole that is large enough – Spares larger holes for subsequent larger requests – Good strategy for real-life programs • First-Fit Algorithm – Object is placed in the first hole in which it fits – Takes less time to place objects – Overall performance is inferior to best-fit
  • 49. Managing Free Space • Coalescing a recently feed chunk to the adjacent free chunk forms larger chunk – We can always use a larger chunk to do the work of small chunks of equal total size • For bins of one fixed size we don’t want to coalesce – Simple to keep track of allocation/deallocation using bit map • 1 indicates allocated • 0 indicates free
  • 50. Problems with Manual Deallocation • Two common mistakes 1. Memory Leak • Failing ever to delete data that will never be referenced • Slow down the program due to increased memory usage • Critical for long running/nonstop program such as OS or server • Does not affect program correctness • Automatic garbage collection gets rid of it – Even the program may use more memory than necessary
  • 51. Problems with Manual Deallocation • Two common mistakes 2. Dangling Pointer Reference • Delete some storage and try to refer to the data in the deallocated storage • Once the freed storage is reallocated any read, write or deallocation via dangling pointer can produce random effects • Dereferencing a dangling pointer creates program error hard to debug