ECS 165B Spring 2011 - Database System Implementation
Warmup Assignment: Serialization and Memory Management
Due Sunday, April 3 at 11:59pm
In this assignment, you will work with two simple C++ classes,
Point and ListNode. Point is a "plain old
data" class holding two integer values x and y
representing a point in two-dimensional space. ListNode is a
slightly more complex class intended to represent a node of a linked
list. You will implement the methods of these classes, including
methods to serialize/deserialize instances of each object to/from a
byte buffer. You will also be required to make sure that neither
class leaks memory when used properly. For the most part the intended
semantics of the classes and the class methods should be self-evident,
but you must additionally think about "reasonable" memory management
conventions, which we deliberately leave unspecified.
For serialize, if the buffer passed in as a parameter is
too small, you should detect this and call assert
to abort the program.
Just to give some additional practice, the method signatures are
slightly different in Point::deserialize and
ListNode::deserialize. These reflect the two alternatives
described in lecture.
Next, you will implement a simple class called
BufferStream to assist in the task of
serialization/deserialization to byte buffers, as discussed in
lecture. The job of BufferStream will be to keep track of
the current read/write position within the byte buffer, and to ensure
that no out-of-bounds array accesses occur (flag these also with
assert). To test the class, you will change
ListNode to use BufferStream in its
serialize/deserialize methods. (Of course, we won't be able to tell
whether you skipped the first step of implementing ListNode
without BufferStream, but you'll get better practice
trying it both ways.)
Finally, you will check for memory leaks using valgrind,
as also discussed in lecture. Unless you've been extra careful,
you'll probably have several; find them and fix them before turning in
your solution.
Unlike the class project, you will do this homework individually.
However, we encourage you to help each other and talk about the
assignment. Please don't cut and paste code, however; the solution
you turn in should be your own. We'll grade the assignment pass/fail
with the bar set fairly low to pass. (But you really ought to spend
some time getting everything to actually work, or you'll regret it
once we start the DavisDB project.)
Getting Started
Download the skeleton file warmup.cpp. You will implement the
methods of the classes defined inside that file, as discussed above.
(Note, it's much better C++ style to put different classes in
different source files with their own headers, and in DavisDB, we'll
be a little more serious about keeping class files organized. Here we
just use a single file for simplicity.)
The file contains a main method that contains some
cursory tests of Point and ListNode. You shouldn't
need to change main (but you are free to do so if you want to
add further tests). The test code inside main will also give
some hints as to the intended usage of Point and
ListNode.
Submitting Your Solution
Submit your solution from the CSIF machines by using handin
as follows:
handin cs165b warmup warmup.c