Programming Languages CS 550 List Processing Dynamic Memory

  • Slides: 6
Download presentation
Programming Languages (CS 550) List Processing, Dynamic Memory Allocation and Garbage Collection Jeremy R.

Programming Languages (CS 550) List Processing, Dynamic Memory Allocation and Garbage Collection Jeremy R. Johnson 1

Theme v This lecture reviews list processing discusses dynamic memory allocation and garbage collection.

Theme v This lecture reviews list processing discusses dynamic memory allocation and garbage collection. v This will allow us to re-implement the list version of the mini language without relying on underlying support for lists. Rather than force the user to explicitly free memory, we will use garbage collection to reclaim unused memory. 2

Outline v. Go over last week’s practice exercises v. Review list processing functions ØList

Outline v. Go over last week’s practice exercises v. Review list processing functions ØList primitives – (), cons, car, cdr, pair? , null? ØList functions – length, append, reverse, reduce, map, order 3

Outline v cons cells and list allocation (uniform size) Ø List diagrams and list

Outline v cons cells and list allocation (uniform size) Ø List diagrams and list cells Ø Overlapping list cells and extent Ø Reference counting Ø Heap v Garbage Collection Ø Mark and Sweep v variable size allocation Ø First-fit Ø Next-fit Ø Best-fit 4

Assignment 4 (Part I v Extend Mini Language and Mini Lang Interpreter Ø Add

Assignment 4 (Part I v Extend Mini Language and Mini Lang Interpreter Ø Add lists to the mini language Ø Values are now lists or ints (modify Environment) Ø Support list constants and built-in list processing functions § § § cons( e, L ) - appends element e to the front of list car( L ) - returns the first element in the list cdr( L ) - returns the rest of the list (minus the first element) nullp( L ) - returns 1 if L is null, 0 otherwise intp( e ) - returns 1 if e is an integer, 0 otherwise listp( e ) - returns 1 if e is a list, 0 otherwise to allow construction and access to lists. 5

Assignment 4 Part II v. Re-implement (mini language with lists) ØAllocate cells through cons

Assignment 4 Part II v. Re-implement (mini language with lists) ØAllocate cells through cons from a Heap (an array of cells) ØImplement Mark & Sweep Garbage Collection § Use symbol table to detect active list variables § Need to be careful with temporary variables used for list constants 6