← Back to team overview

dolfin team mailing list archive

Re: smart pointers

 

On 10/23/06, Anders Logg <logg@xxxxxxxxx> 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)

There are probably places where we could make good use of smart
pointers, but here it looks to me like it just adds complexity.

In our experience, just taking care of sizes is not usually enough. We
want reference
counting in there too, so we wrote our own (they do not have array sizes).
However,
I will note that you can remove all the get() calls with a suitably defined
cast operator.

 Matt
--
"Failure has a thousand explanations. Success doesn't need one" -- Sir Alec
Guiness

Follow ups

References