Due: Monday, November 14 2015, 11:59 pm

Part I: Memory Management in C


This part is to try and estimate the big O complexity and time cost of memory management in C. There are two main questions.

There are many ways to time code. One is to use the ftime library call, which returns a time stamp you can use to estimate total run time reasonably well. Don't try to use it to time small things. But it works ok to use for stuff that takes at least a quarter-second.

The second way to time code is to use a profiler. On a Mac, you can use Activity Monitor, which you can find in the Instrument. On a linux machine, you can use a tool called gprof. You can use gprof on any of the dwarves (linux machines) in the robotics lab.

Part II: Memory Management in Selected Languages


This part is to do some research on memory management in your two languages.

  1. Do your best to research what memory management algorithms your languages use.
    • If your language has explicit allocation/deallocation, then create some code examples.
    • If your language requires allocation, but not deallocation, then create some code examples. Show some side-by-side comparisons of the differences between C and your language.
    • If your language pretty much hides memory allocation, show a variety of statements that create memory, and a variety of conditions whereby that memory gets lost (or put back into a free memory pool).
  2. Undertake an experiment in a language with automatic memory management (Python, if neither of your languages fits the model), and see if you can identify when a garbage collection sweep takes place. Create and delete lots of memory inside a function and time the function as you call it many times. Look for times when the function call takes significantly more time than average.


  1. Describe memory management for a third language.
  2. For the memory management example, try writing a functionally equivalent example in C, explicitly handling the kinds of information required for the memory management system of your chosen language.
  3. Write a compilable haiku on memory management.
  4. Using a profiler to test your code counts as an extension.


The submission of this project has three components:

  1. Codes: The source codes for all your experiments in C and the selected languages should be submitted to the fileserver. Please make the filename of your source codes reflect the tasks or extensions.Note that the quality of your comments counts toward your grade.
  2. README: In this project, you need to submit a README file for your source codes in C and the selected languages. The README file can be a .txt file. It should be well-organized in a way that readers can easily know the usage and the outputs of every source files. Please explain the results of your experiments in C if the outputs are not meaningful to readers. In addition, the known bugs of your codes should also be indicated in the README file. Please also indicate the version of your C complier, your operationg system, and its version in the README file.
  3. Wiki write-up: The write-up of this project should have the following elements.
    • Title of the project and your name
    • The tutorials on memory management in the selected languages (task 1 and 2 of part II)
    • Please include necessary code snapshots in your tutorials.

Please note that it is your responsibility to explicitly indicate the extensions you have taken. If you take the extension in C, please indicate explicitly in the codes and README file. If you take the extensions in the selected languages, please indicate explicitly in your wiki write-up or source codes and README.

© 2016 Ying Li. Page last modified: .