This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS106X Handout 22S Autumn 2010 October 18 th , 2010 Section Solution Solution 1: Farmers Market Memory Trace The drawing above depicts the state of memorystack on the left, heap on the rightat the moment the problem asks for a snapshot of memory (right before the call to FarmersMarket ). All dynamically allocated memory is drawn from the heap, and all local variables (in this case, salad and currant ) are allocated on the stack. The next page includes an elaborate drawing detailing the state of memory just after a base case is detected but just before the recursive call returns. [Note that no memory is orphaned at all, since everything is accessible from some active local variable.] apple banana date cherry[0..3] salad 7 apple banana date cherry[0..3] currant false 2 apple banana date cherry[0..3] salad 17 apple banana date cherry[0..3] currant false stack frame for main stack frame for first call to FarmersMarket apple banana date cherry[0..3] 14 false grape lemon lime 20 true...
View Full Document
This note was uploaded on 01/13/2011 for the course CS 106X taught by Professor Cain,g during the Fall '08 term at Stanford.
- Fall '08