Question: Python Garbage Collector Summary create a Python program (hw3.py) that simulates a Mark-Sweep garbage collection algorithm. In this program, named pointers are referred to using

Python Garbage Collector

Summary

create a Python program (hw3.py) that simulates a Mark-Sweep garbage collection algorithm. In this program, named pointers are referred to using variable names such asp,stackPtr,temp3, etc. Heap blocks are referred to using integers.

The program has the following functionality:

  1. Get the name of an input file from the command line (usingsys.argv). WARNING: Do not prompt the user for a file name.
  2. Process the file. The first line will containnnumber of heap blocks--the heap blocks will be identified using the numbers 0 throughn - 1. Each subsequent line will contain an ordered pair either in the form :
  • named pointer, heap block(example:p,10meansppoints to heap block 10)
  • heap block, heap block(example:7,3means heap block 7 points to heap block 3)
  1. Perform the mark-sweep algorithm.
  2. Output which heap blocks are marked and which heap blocks should be reclaimed (swept).
  3. The program must contain a function namedmark_sweepthat takes a filename string and returns a dictionary with two string keys 'marked' and 'swept' where the values for the 'marked' key is the ordered list of integers which are the marked nodes you'll print out and 'swept' is the ordered list of integers which are the swept nodes you'll print out. You can assu
    Python Garbage CollectorSummarycreate a Python program (hw3.py) that simulates a Mark-Sweep garbage

Example Diagram of heap: P O 7 3 N s -7 6 8 K

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!