Some authors argue that an explicit stack is not necessary, and
is indeed the responsiblity of the compiler (See Eckel
[#!EK:UC!#]). The problem with this approach is that using the
program stack to keep track of the temporary matrices allows the
temporary matrices to stay on the stack until they go out of
scope. They hang around and cause stack overflows in large
subroutines. This happens even if the stack only contains a
reference to a matrix instead of a copy. This problem was discussed
by Davies in his matrix program Newmat (currently available in
the Borland C++ library on Compuserve).
The advantage to having an explicit stack is that you can
control the deletion of the temporary matrices. The
Cleanstack()
function can be used for garbage collection
of temporary matrices. It is called in matrix assignment, and
the copy constructor. It is also a public function, so it may
also be called explicitly. It's my opinion that the overhead of
manipulating an explicit stack outweighs the storage problems
and stack overflow problems of letting the program stack do it
for you. Besides, I couldn't figure out how to let the program do
it for me.