[dune-pdelab] More constructors for ISTL***Container [patch]

Markus Blatt markus at dr-blatt.de
Mon May 12 17:09:05 CEST 2014


Hi,

On Sat, May 03, 2014 at 08:16:50AM +0200, Oliver Sander wrote:
> Dear PDELab,
> please find attached two small patches for the ISTL backend.
> [...]
> +      template<typename GO>
> +      ISTLMatrixContainer (const GO& go, Container& container)
> +        : _container(Dune::stackobject_to_shared_ptr(container))
> +      {
> +        _stats = go.matrixBackend().buildPattern(go,*this);
> +      }
> +
>        template<typename GO>
>        ISTLMatrixContainer (const GO& go, const E& e)
>          : _container(make_shared<Container>())
> [...]
> +      ISTLBlockVectorContainer (const GFS& gfs, Container& container)
> +        : _gfs(gfs)
> +        , _container(stackobject_to_shared_ptr(container))
> +      {
> +        _container->resize(gfs.ordering().blockCount());
> +        istl::dispatch_vector_allocation(gfs.ordering(),*_container,typename GFS::Ordering::ContainerAllocationTag());
> +      }

I might be missing something here, but to me these patches might tempt
users to shoot themselves in the foot due to lifetime issues.
(Not that there are not a lot more places where this can be done, but
...). There might be cases where the outer container might go out of
scope and the shared pointer becomes invalid.

Personally, I would prefer the constructor to take a shared_ptr of
the container. This way the user has to take care of the case where
the container is only available as a reference him/herself (and
hopefully knows what he is doing). Is there a reason to prefer a
reference over a shared pointer?

Just my 2 cents,

Markus
-- 
Do you need more support with DUNE or HPC in general? 

Dr. Markus Blatt - HPC-Simulation-Software & Services http://www.dr-blatt.de
Hans-Bunte-Str. 8-10, 69123 Heidelberg, Germany
Tel.: +49 (0) 160 97590858
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <https://lists.dune-project.org/pipermail/dune-pdelab/attachments/20140512/4bb40917/attachment.sig>


More information about the dune-pdelab mailing list