← Back to team overview

dolfin team mailing list archive

Re: Ownership

 

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.

A common reason to use pointers other than when passing
ownership is to allow a null pointer. Any other reasons?

Using a host of different smart pointers will probably just be
confusing to most users. I think we should stick with the
std::tr1::shared_ptr if we need one, unless there are very good
reasons otherwise.

If we use one, I expect it to be shard_ptr. It might be unfamiliar to a user, but it will protect them against themselves because they won't need to explicitly free the memory.

Garth

(Also, the newest version of swig is supposed to
support shared_ptr in the python interface, but I don't know how
exactly).




Follow ups

References