← Back to team overview

dolfin team mailing list archive

Re: smart pointers

 

On Mon, Oct 23, 2006 at 06:24:51PM +0200, Garth N. Wells wrote:
> 
> 
> Anders Logg wrote:
> > On Mon, Oct 23, 2006 at 02:57:27PM +0200, Garth N. Wells wrote:
> >> What does everyone think about using some of the smart pointers from
> >> Boost? Instead of
> >>
> >>   int* nodes = new int[element.spacedim()];
> >>   element.nodemap(nodes, *cell, mesh);
> >>   /*
> >>      Do something
> >>   */
> >>    delete [] nodes;
> >>
> >> we would have
> >>
> >>   boost::scoped_array<int> nodes( new int[element.spacedim()] );
> >>   element.nodemap(nodes.get(), *cell, mesh);
> >>   /*
> >>      Do something
> >>   */
> >>
> >> In the end, it's pretty similar to std::vector, except it's a bit more
> >> efficient since it's not designed to change size and we can access the
> >> underlying pointer with get().
> >>
> >> Garth
> > 
> > To me, it looks like code obfuscation. If you compare the two ways of
> > writing, you remove
> > 
> >   "int*", "delete [] nodes"
> > 
> > and add
> > 
> >   "boost::scoped_array<int>", ".get()", ".get()" (get in two places here)
> > 
> 
> I agree that it doesn't do a lot for readability. The advantage is that
> you don't have to worry about "delete" and the consequent memory leak if
> you forget it.
> 
> Smart pointers would definitely by useful for sub-functions which refer
> to the same vector.

I agree completely. Then we could probably avoid all the "bool
foo_local" stuff that goes on in DiscreteFunction.

/Anders


> Garth
> 
> > There are probably places where we could make good use of smart
> > pointers, but here it looks to me like it just adds complexity.
> > 
> > /Anders
> > _______________________________________________
> > DOLFIN-dev mailing list
> > DOLFIN-dev@xxxxxxxxxx
> > http://www.fenics.org/mailman/listinfo/dolfin-dev
> > 
> 
> 
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/dolfin-dev


References