Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Projects

  1. Devise and conduct a set of experiments to measure garbage collection overhead. For example, write a program that creates a specified number of garbage objects as quickly as possible. Determine the number of objects needed to trigger garbage collection. Measure the running time of your program when no garbage collection is performed and compare it to the running time observed when garbage collection is invoked.
  2. C# provides the means for accessing memory directly by using pointers  and unsafe  blocks. Therefore, we can simulate a heap using a C# array of ints. Write a C# class that manages an array of ints. Your class should implement the following interface:
    public interface Heap
    {
        int Acquire(int size);
        int Release(int offset);
        int this[int offset] { get; set; }
    }
    The Acquire method allocates a region of size consecutive ints in the array and returns the offset of the first int in the region. The Release method release a region of ints at the specified offset which was obtained previously using Acquire. The indexer this[] provides get and set accessors to access a value in the array at a given offset.
  3.   Using an array of ints simulate the mark-and-sweep garbage collection as follows:
    1. Write a class that implements the Handle interface given below:
      public interface Handle
      {
          int Size { get; }
          int GetInt(int offset);
          Handle GetReference(int offset);
          SetInt(int offset, int value);
          SetReference(int offset, Handle h);
      }
      A handle refers to an object that contains either ints or other handles. The size of an object is total the number of ints and handles it contains. The various store and fetch methods are used to insert and remove items from the object to which this handle refers.
    2. Write a class that implements the Heap interface given below
      public interface Heap
      {
          Handle Acquire(int size);
          void Release(Handle h);
          void CollectGarbage();
      }
      The Acquire method allocates a handle and space in the heap for an object of the given size. The Release method releases the given handle but does not reclaim the associated heap space. The CollectGarbage method performs the actual garbage collection operation.
  4. Using the approach described in Project gif, implement a simulation of mark-and-compact garbage collection.
  5. Using the approach described in Project gif implement a simulation of reference-counting garbage collection.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.