CS 1621

 Structure of Programming Languages

Programming Project, Part B

 

Handed out: Wednesday, November 9, 2005

Due: Monday, December 5, 2005 by the BEGINNING of class

Late Due Date: Wednesday, December 7, 2005

 

Before reading this handout, make sure you have thoroughly read and understood Part A of this assignment, handed out last week.

 

Once you have your heap set up as described in Part A of this assignment, you will run a simulation to see how well different allocation schemes work by measuring several things: 1) The number of allocation requests that are denied due to lack of a large enough memory chunk 2) The fragmentation of the memory as shown by the number of chunks of various sizes that are available and 3) The average time required for an allocation block to be located.   The allocation schemes that you will use will be as follows:

1)      First Fit – for a request of a given size, allocate the FIRST block found in the free list that is >= to that size

2)      Best Fit – for a request of a given size, allocate the SMALLEST block found in the free list that is >= to that size.  If you find an exact size match, clearly that block can be used without further searching.

3)      Worst Fit – for a request of a given size, allocate the LARGEST block found in the free list that is >= to that size, unless an exact match is found, in which case the exact match can be used. 

 

You should run your simulation separately on each of the three allocation schemes, with several different parameter values.  The parameters are:

MaxS – Initial size of the heap

MinB – Minimum allocation block size

MaxB – Maxium allocation block size

InitNum – Number of blocks allocated to initialize the heap

In your simulation you should:

1)      Start with your heap being empty, as described in Part A of this assignment.  Then initialize it by doing InitNum memory allocations of random size in the range MinB bytes – MaxB bytes (using multiples of MinB bytes).

2)      Once your heap has been initialized, do 1,000,000 random requests, each of which (with equal probability) will be one of the following 2 forms:

a)      A memory allocation in the range MinB-bytes – MaxB bytes (in multiples of MinB bytes)

b)      A random memory deallocation.  Do this by simply choosing a random node in the Used list and freeing it.

Keep track of how many requests (if any) are denied.  Also keep track of the average fragmentation of the heap in the following way:

a)      Every 500 requests examine the Free list and count the number of available blocks in ranges incremented by (MaxB – MinB)/16 bytes (in other words, you will count ~16 different block sizes: [0-(MaxB-MinB)/16), [(MaxB-MinB)/16 – 2(MaxB-MinB)/16), …

b)      After your simulation is complete, calculate the average number of blocks available in each group throughout the run of the program and store these results.  Also calculate the percentage of denied requests.

Finally, keep track of the overall time required for your requests, and also the average time per request.  The system clock may not have a high enough resolution to accurately time each request, so you will likely be better off timing groups of requests together (ex: 500 at a time).

 

Note: In order for the time results of this simulation to be meaningful, you must do all of your runs on as close to identical conditions as possible.  This means the same computer with (as much as possible) the same setup.

 

Experiment with different values for your parameters to see if you get different results.  For example, how do your results vary as you change MinB, MaxB and MaxS.  As a suggestion, try some extremes (MaxB very large – close to MaxS vs. MaxB relatively small compared to MaxS;  MinB and MaxB close to each other vs. MinB and MaxB far apart).  Also consider the effect of increasing InitNum prior to doing your random requests.  I am leaving the specifics of the parameter choices up to you, but you should do your best to make your results interesting.  Whatever your parameter choices, be sure to run them using all 3 allocation schemes.

 

Once your simulations are complete for all parameter variables on all 3 allocation schemes, write up your results in the following way:

1)      Clearly indicate all of your results for each allocation scheme with all parameter choices including:

a)      The number and percentage of denied requests

b)      A nicely formatted graph showing the average block-size distribution throughout each of the simulations.  A good way to show this is using a bar graph.

c)      The total and average time required for the requests.

2)      Write a short (~3 page, double-spaced) paper discussing your project and the 3 allocation schemes.  Be sure to minimally address each of the following issues:  Was there a significant difference in the denied requests or the fragmentation for the 3 schemes?   If so, which appeared to be the best and which appeared to be the worst?  How, if at all, did each of the schemes vary with changes in the parameter variables.  If they did vary, for which configuration were they best and for which were they worst?  Speculate as to why differences occurred or why they did not.  If you had NOT combined neighboring blocks into larger blocks, how do you think it would have changed your results (if at all)?

 

You may do your program in either C, C++ or Java.  If you REALLY want to use a different language, you must see me to discuss it first.

 

Submit the following materials electronically by the due date:

1)      All of your source and executable program files

2)      Your completed paper, results and graphs

3)      An information sheet stating all of the following information (this should be the first sheet):

a)      Your name and email address

b)      The language and compiler that you used for your project.  If you use a compiler / interpreter that is not generally available, you may have to demonstrate your program to the TA directly.

c)      The names of all source and executable files and what each is (especially if you have many)

d)      Any problems, special features, extra credit, or ANYTHING ELSE that will be useful to the TA when grading your project.

You will submit all of these materials to a submission directory created for you for this course.  I will send you more information on the submission directory when I have completed it.