Virtual Function binaryStoreSize()
The binaryStoreSize() virtual function calculates the number of bytes necessary to store an object using RWFile. The function is:
 
virtual Rwspace binaryStoreSize() const;
This function is useful for classes RWFileManager and RWBTreeOnDisk, which require allocation of space for an object before it can be stored. The non-virtual function recursiveStoreSize() returns the number of bytes actually stored. Recursive store size uses binaryStoreSize() to do its work.
Writing a version of binaryStoreSize() is usually straightforward. You just follow the pattern set by saveGuts(RWFile&), except that instead of saving member data, you add up their sizes. The only real difference is a syntactic one: instead of insertion operators, you use sizeof() and the member functions indicated below:
*For primitives, use sizeof();
*For objects that inherit from RWCollectable, if the pointer is non-nil, use function:
 
RWspace RWCollectable::recursiveStoreSize();
*For objects that inherit from RWCollectable, if the pointer is nil, use the static member function:
 
RWspace RWCollectable::nilStoreSize();
*For other objects, use member function binaryStoreSize().
Here is a sample definition of a binaryStoreSize() function for class Bus:
 
RWspace Bus::binaryStoreSize() const{
RWspace count = RWCollectable::binaryStoreSize()
+customers_.recursiveStoreSize()
+sizeof(busNumber_)
+driver_.binaryStoreSize();
if (passengers_)
count += passengers_->recursiveStoreSize();
else
count += RWCollectable::nilStoreSize();
return count;
}