CS 333: Assignment #6

Memory Management

This assignment is about memory management...


  1. The first task is to try and estimate the big O complexity and time cost of memory management in C. There are two main questions.
    • What is the average time per call to allocate a certain amount of memory?

      Try timing several hundred/thousand calls to make the estimate, and try the experiment with at least three different memory sizes (small, medium, large).

    • Does the time of a memory management call change with the number of allocation and free operations the program has executed?

      You can test this by writing a program that makes lots of both types of actions and timing either one call (which might be hard), or timing a few hundred calls (which is probably easier) over a period of time.

      See if it makes a difference when you allocate/free the same size memory space versus many different sized memory spaces.

    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 an Intel mac, you have to use a mac developer tool called Saturn, which you can get from developer.mac.com. On a linux machine, you can use a tool called gprof. These tools actually calculate useful statistics on every function call made in the program and measure actual run time, not just system time. I strongly suggest trying out gprof or Saturn. You can use gprof on any of the dwarves (linux machines) in the robotics lab.

  2. The second task is to do some research on memory management in your two languages. 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).
  3. 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.



The writeup for this week is the assignment itself, plus the code, which should be integrated with your writeup (except for the C experimental code). Once you have written up your assignment, give your main page for this week the label:


Put the C experiment code in your private handin folder on the Courses volume.