Discuss array bounds checking on the heap
Talk about pointers, reference values, copy constructors, destructors, and assignment
Memory error/leak detection using valgrind
We will look at some code examples - These code examples can be found in the shared folder, under obj_creation_deletion:
Allocating arrays and bounds checking
Pointers
Calling a copy constructor
Calling an overloaded assignment operator
Calling a destructor
We will run valgrind to show memory errors.
valgrindTo run valgrind do:
valgrind ./executable_file
Run valgrind on your test programs to make sure there are no memory problems or if something unusual is happening.
A Makefile can be configured to run valgrind on test programs.
There is a close connection between arrays and pointers.
Note how in the last example the pointer variable is used like an array once it has memory allocated.
We need to:
Update the shared folder in your home directory
Create a directory called object_construction in your cs23001 folder
Copy obj_creation_destruction.cpp and array_bounds_check.cpp from the shared directory into object_construction.
Create object_construction.cpp, object_construction.hpp, and object_test.cpp in the object_construction folder.
object_construction.cpp is for your implementation
object_construction.hpp is for the class
object_test.cpp is where your main function and tests should go.
The first part of this lab is to open array_bounds_check.cpp in an editor and read over the code. There are instructions on how to compile and run the code. There are some questions to answer about the code and the various runs.
The next part of the assignment is an excercise about constructors and assignment calls. Your job is to write a small program (a class, an implementation, and a main) that calls the copy constructor, default constructor, assignment, and destructor.
It should output a message every time one of these are called: "Called {Function}". After you've done so, look at the examples in shared and answer a few questions about how objects are constructed and deleted.
The following should be true when you are done, NAMES MUST MATCH EXACTLY:
In your cs23001 directory you have created a directory named object_construction .
In the directory object_construction you have the following files:
The array_bounds_check.cpp file with answered questions
object_construction.cpp, object_construction.hpp, and object_test.cpp
There are NO executables in the repository.
Your programs compile, run, and perform as specified.
Your programs follow the General Program Requirements.