Project 0: Memory Management and Using GL
Due: Friday, Sept. 13, before 9:00 pm
There are no late submission folders for Project 0. You must turn it in on time to receive credit.
Addenda
- The type of m_size has been changed from int to unsigned int to eliminate a warning message when compiling the test programs with the -Wall flag.
- In addition to writing the copy constructor, destructor, and assignment operator, you must complete the test of the assignment operator in test1.cpp
Objectives
- Review C++ memory management, including copy constructors, destructors, and assignment operators.
- Use Valgrind to check for memory leaks.
- Review the procedures to access the GL servers and to compile programs on GL.
- To ensure that you are able to submit project files on GL.
Introduction
In this project, you will complete a C++ class by writing a copy constructor, destructor, and assginment operator. Furthermore, you will use Valgrind to check that your program is free of memory leaks. Finally, you will submit your project files on GL. If you have submitted programs on GL using shared directories (instead of the submit command), then the submission steps should be familiar.
Assignment
Step 1: Create your working directory
Create a directory in your GL account to contain your project files. For example, cs341/proj0.
Step 2: Copy the project files
Change to your working directory (using the cd command) and copy the project files with the following command:
Step 3: Complete the my_array class
The my_array class implements a simple, dynamically-allocated array with bounds checking on the element access operator. Complete the class by implementing the copy constructor, destructor, and assignment operator for the my_array class. You will need to add function prototypes, given below, to the header (.h) file and implement the functions in the .cpp file.
Step 4: Test your program
There are two test programs provided, test0.cpp and test1.cpp. However, test1.cpp is incomplete, and you must finish writing the test code for the assignment operator.
Be sure that both test programs compile with your completed my_array class and that they produce correct output.
Note: it is not sufficient for the test programs to compile and run. Both programs will compile and run even if you do no work on the project, but test1.cpp will give incorrect results. You must check that your output is correct.
Step 5: Check for memory leaks
Run the test programs using Valgrind. For example, assuming you have compiled test1.cpp, producting the executable test1, run the command
If there are no memory leaks, the end of the output should be similar to the following:
The important parts are “in use at exit: 0 bytes” and “no leaks are possible.” The last line is also important as memory errors can lead to leaks.
Step 6: Link your shared directory
Do not complete Steps 6 and 7 until directed to do so by your instructor. The submission directories will not be created until after the last day to add a class (Sept. 11).
Follow the instructions on the Project Submission page to make a symbolic link to the shared directory in your home directory.
Step 7: Submit your files
See the “What to Submit” section, below.
Implementation Notes
Each project has a section on implementation notes. These point out some issues that you might encounter while developing your code. You should look through the Implementation Notes before you start coding.
For Project 0, there are only a few notes:
-
The files my_array.h, my_array.cpp, test0.cpp
and test1.cpp are available on GL in the directory:
/afs/umbc.edu/users/c/m/cmarron/pub/www/cs341.f19/projects/proj0files/ - You must add the prototypes for the copy constructor, destructor, and assignment operator to my_array.h and implement these functions in my_array.cpp.
- Apart from adding the required prototypes, you may not modify my_array.h in any way.
- You should read through the coding standards for this class.
What to Submit
You must submit the following files to the proj0 submit directory:
- my_array.h
- my_array.cpp
- test0.cpp
- test1.cpp
If you followed the instructions in the Project Submission page to set up your directories, you can submit your code using the following command: