Task

Consider the following C++ code: See image.

Because a virtual method call is resolved at run time, calling f1 will be slower than calling f2, and an object of class C1 will be larger than an object of class C2. But by how much?

Your task is to devise and conduct an experiment that measures the extra overhead (in both time and space) of the virtual function mechanism in C++, then report on your findings. Imagine that your goal is to provide advice for programmers considering whether or not to use the virtual mechanism for a critical section of code. Ideally, you should offer guidelines on which programmers could base their decisions without having to undertake their own experiments.

Report

Your report should include at least the following elements:

  • An overview of the difference between virtual functions and non-virtual functions, outlining why the virtual mechanism is needed in an object-oriented language, and why it has a run-time cost.
  • A survey of the relevant literature focussing on similar investigations done by others.
  • A description of your experiment, including explanations for the key design decisions you made and providing sufficient detail for a reader to be able to reproduce your results.
  • A summary of your results, and a discussion of what they mean and of the conclusions you draw from your work.

In preparing and writing your report you will need to survey relevant material that others have written. Of course, you must make sure that you acknowledge any material that you use or reference in your report, including diagrams, tables, and the like. Use an established convention, such as the Author-Date ("Harvard") system, for citations and bibliography.

Assessment

Your report should consist of a typed document of around 2500 words that conforms to accepted norms for style and presentation of written work. You will be assessed on your insight into the relevant issues, the clarity with which you have presented your ideas, and your attention to writing style and presentation details.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.