Public Parts of a vdoub

The public functions give access to the vmm. The function Garbage() simply checks if the signature is correct. This indicates that the vdoub is likely intact and active.

The constructors accept void, long or vdoub& arguments. The default constructor accepts a void. It allocates a hdr on the vmm with one double. The second constructor does the same, but the hdr contains array_size elements. The constructor with a vdoub reference argument copies one vdoub into another. Each constructor increments nobj, and calls vopen() if nobj is zero.

The destructor frees the header. If the hdr is freed with error, the system stops. Otherwise, the signature is set to zero and nobj is decremented. If nobj is decremented to zero, then vclose() is called. Note that this does not guarantee that vclose() will be called when the program leaves the main() function because some virtual matrices are constructed outside of the scope of main(). The matrix stack dispatcher is a pointer to the base of a stack of matrices. It is allocated outside of the function main() so it will not be destroyed upon leaving main(). Thus, vclose() must be called before leaving main(). The next time the destructor is called, vfree() will return an error so the program will exit through the last destructor call.

The function v() gets the value at index. It calls vread() and returns the value. It also sets cur_index to index, and stores the current value in *cur_ele. Note that the call to vread() may change the page the buffer in vmem.

The brackets operator provides the same function as v(), but you can use the vector notation to do it. However it is basically very different than accessing an element on the heap, or some offset from a pointer base. The call to vread() shifts a new page into RAM if necessary. The normal use of the brackets operator just accesses RAM. This has side effects in the assignment operation on virtual vectors.

The difference between v() and the brackets operator is they have different return types. v() returns a double and vdoub::operator[] returns a reference to another vdoub. To quote Holub:

The brackets operator is a selector operator. It sets things up so that the next operation can access the array element selected by the previous bracket. If the next operation modifies the array element, then that operation sets the dirty bit.