← Back to team overview

dolfin team mailing list archive

Re: Ownership

 



Martin Sandve Alnæs wrote:
2008/6/26 Garth N. Wells <gnw20@xxxxxxxxx>:
Martin Sandve Alnæs wrote:
If we can use references somewhere we use pointers, we should change
that. All factory functions will of course return pointers, and they
clearly give away ownership to the caller. Where else do we need to
use pointers?
DiscreteFunction is an example where we use a number of pointers because a
DiscreteFunction may or may not own the data. Without having a bunch of
constructors, I don't know how to tell DiscreteFunction what it does and
doesn't own.

Pointers are also used quite a bit in DofMap and DofMapSet. These of course
will be overhauled in the near future.

Ok. Also, we should allow FooVector and FooMatrix to be a "view" of an
object they don't own, or take over ownership. This may be important
if somebody tries to use dolfin as a component on the side and not the
main application framework, e.g. if they have an existing PETSc Mat or
Epetra_FEVector to use. Both are possible with shared_ptr, possibly
with custom deleters in special cases.


I'll play around with this for the NewtonSolver to experiment as it's pretty unobtrusive. At the moment NewtonSolver owns the Jacobian matrix, but I'd like to set it up such that the NewtonSolver can create and own the matrix (which will be the case 95% of the time), or a user can supply the matrix which NewtonSolver may or may not then own. A reason a user might want to supply a matrix is to specify a special matrix type (say a PETSc UMFPACK matrix).

Garth


--
Martin




Follow ups

References