This part 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
Try timing several hundred/thousand calls to make the estimate, and
try the experiment with at least three different memory sizes (small,
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
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 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
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).
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.
Describe memory management for a third language.
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.
Write a compilable haiku on memory management.
Using a profiler to test your code counts as an extension.
The submission of this project has three components:
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.
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.
Wiki write-up: The write-up of this project should have the following
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.