Skip to content

Instantly share code, notes, and snippets.

@jcasimir
Created October 29, 2018 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcasimir/87a5b51fac3c699c8dc3d61ce4632bb0 to your computer and use it in GitHub Desktop.
Save jcasimir/87a5b51fac3c699c8dc3d61ce4632bb0 to your computer and use it in GitHub Desktop.

Exploring a Variable-Length Array

  • You've been provided the "snapshot" of a heap with 64 addressed slots link to printable map
  • The marker for "Array Start" is 126
  • The slot after an "Array Start" is the address of the first value
  • The slot after that first value is the address of the second value
  • The slot after the second value is the address of the third value, and so on
  • The marker for "Array End" is 127
  1. Write out the values in this array in normal JavaScript notation
  2. Modify your heap by adding a new value, 112, on to the end of the array. You should only change the values stored in three slots of the heap (two blanks, one with existing data).
  3. Modify your heap by adding a new value, 111, to the beginning of the array. You should only change the values stored in three slots of the heap.
  4. You can count the number of elements by following one link after another. How many "jumps" does it take to get from the Array Start to the Array End? How does this compare to the count? What formula would you write to find the number of data elements relative to the number of jumps?
  5. Extension: Remove the fifth element of the current array by only changing the value of one slot. What does this imply about the relationship between variable-length arrays and garbage collection?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment