dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #07586
Re: Ownership in general
On Wed, Apr 23, 2008 at 11:24:33PM +0200, Martin Sandve Alnæs wrote:
> Dag recently discussed issues with object ownership in the context of
> Vector and DiscreteFunction. Are there any existing general
> conventions for this in DOLFIN? It's not easy to know which function
> arguments will be kept references to, which will be assumed ownership
> of and later deleted, and which return value pointers you yourself
> should assume ownership of.
>
> In the absense of reference counting, the least we should do is agree
> on some conventions to make this easier, and be very careful to
> document this next to each relevant function. However, doing this
> requires some overview of many parts of the code, so it's not quickly
> done. I guess this should be thought of during the Function cleanup?
As a first rule, we never assume responsibility for data given as
pointers/references. So if you do
Foo foo(mesh);
then that means foo needs to have access to the mesh but does not
assume responsibility for deleting it.
Then there are exceptions to this rule. For example, when doing
Function u = w[0];
Function p = w[1];
Here u and p will be responsible for their own vectors since no one
explicitly creates those vectors.
Then there's also the recent exception Dag added.
In general, I think we should let C++ be C++, which means I don't
think it's a good idea to use smart pointers everywhere.
--
Anders
Follow ups
References