[CLN-list] modular polynomials
bruno at clisp.org
Sun Sep 28 11:28:37 CEST 2008
> > And in CLN these simple assignments are only copying a simple reference,
> > not the deep contents (see the other mail).
> In C++ "deep copying" is typically called operator=.
Rather, in C++, "deep copying" is the default for operator= and copy constructor.
In those areas where this is not appropriate, people use "smart pointers".
I did not invent this idiom. It is widely used.
The reasons why CLN uses smart pointers for everything are:
1) Its main purpose is to allow the formulation of mathematical algorithms
directly in C++. As in a scripting language. Without requiring the
programmer to think in terms of memory allocation. The programming model
of a scientist in this case is to manipulate opaque values that are
elements of rings. CLN brings the philosophy of computer algebra
languages into C++.
2) When you do computations with polynomials, you need a maximum of sharing
of the polynomial representations. This is the basic implementation
principle of Maple. In systems where deep copying of polynomials is the
default, you cannot do computations as large as those possible in Maple
- because you run out of memory earlier.
In this light, set_coeff and finalize must be implemented as copy-on-write
operations: create a deep copy implicitly when the reference count is > 1.
No explicit method for deep copying is then needed at all.
More information about the CLN-list