Starting Point Code
Start by creating a week05
directory in
your cs44/weeklylabs
subdirectory and copying over some files:
cd ~/cs44/weeklylabs
mkdir week05
cd week05
pwd
/home/you/cs44/weeklylabs/week05
cp ~newhall/public/cs44/week05/* .
ls
Makefile ptrarith.cpp
Pointer Arithmetic
In the next assignment you may want to use pointer arithmetic. Let’s briefly first look at a program that uses pointer arithmetic, from the code you copied over today:
vim ptrarith.cpp
When using pointer arithmetic, keep in mind is that adding 1 to a
pointer increases its value by the number of bytes in the type it points
to (for char
pointer by 1, for int
pointer by 4 (sizeof(int))).
In other words, adding 1 to a pointer makes it point to the very next valid storage location of the type to which it points (the next valid address location of the type to which it points). For an int pointer, adding one increases its value by 4 (the next valid int address is 4 bytes past the current one). For a char pointer, adding one increases its value by 1 (the next valid char address is 1 byte past the current one).
Here is some more information from Dive into Systems Chapter 2.9.4.
Intro to Lab 4
We are going to talk a little about the next lab assignment, the Heap Page structure and C++ type casting in particular, then get you going on the check point.
-
We are going to start by talking about the HeapPage and Page classes, and looking at C++ type re-casting a Heap Page structure view onto Page memory. The slides are available here: Slides on mapping types on top of Pages.
-
Next, start on
chkpt.cpp
. You should try to pass the first unittest in lab today, and continue adding functionality and testing in this order:-
try to pass
initializeHeader
test suite:./ckpt -s initializeHeader
-
getSet
test suite:./ckpt -s getSet
-
freeSpace
test suite:./ckpt -s freeSpace
(note:
./chkpt -h
doesn’t list thefreeSpace
test suite option but you can run it using-s freeSpace
).
-
-
Note that for this assignment you are required to develop and add tests to
unittests.cpp
. Next week we will talk about this more, but keep this in mind as you are implementing and testing your code (theunittests.cpp
tests are incomplete; they DO NOT fully test the correctness of your heap page implementation).
Reminder of Some resources that will help with Lab 4:
-
Use
gdb
andvalgrind
to debug. Chapt. 3 of Dive into systems covers both with examples and lists of gdb commands. -
Look at the SwatDB Exceptions documentation off the SwatDB info page. It has examples of throwing and catching SwatDB exceptions, and links to the exception class documentation.
-
Refer to the Lab assignment page often for information, tips, about implementing and testing your solution.
-
Refer to the Testing part of the assignment page for some testing tips. Look at the note about the print methods of the BufferManager class to print out information about its state. You can call these from any of the test programs, or from within gdb.
-
Refer to the Details part of the assignment page for more verbose information about the methods you need to implement.
-
Also, look at
heappage.h
for types, parameters, return values, and the SwatDB section for links to documetnation on other parts of SwatDB that is particularly useful for this lab (SwatDB types and the Disk Manager interface).
-
-
Use gdb to debug your code. If you don’t know what a method you wrote is doing, run the test program (
sandbox
,unittest
,checkpt
) in gdb, set break points in HeapPage methods and examine runtime state. -
Use valgrind to make sure any bugs you have are not due to memory access errors.
C++ Reminders
Look at the Wed Lab from Week 1, Wed Lab from Week 2, and Wed Lab from Week 3pages for reminders about specify C++ programming and debugging tools and example programs we tried out for practice.
Use gdb
and valgrind
to help you debug.
It will save you hours and hours of debugging
time to uses these tools, and we will ask you what you discovered
from gdb
and valgrind
about bugs you have in your program that you
want us to help you with--we expect that you are using
gdb
and valgrind
to debug.
The Lab 4: SwatDB Heap Page assignment page has links to all kinds of C++ programming resources.