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

Oliver Sander sander at igpm.rwth-aachen.de
Mon May 12 17:24:38 CEST 2014


Am 12.05.2014 17:09, schrieb Markus Blatt:
> 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.

This was intentional.  The goal was to allow to code simple algorithms
simply, in this case: create a matrix object on the stack -- assemble
into it -- solve -- done.  I don't want to have to explain reference
counting just for this.  If you have more complicated scenarios you are
still free to use shared_ptrs.

In my view this follows the C++ philosophy: give the users lot's of freedom,
in particular the freedom to shoot themselves in the foot :-)

Cheers,
Oliver

> (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
> 
> 
> 
> _______________________________________________
> dune-pdelab mailing list
> dune-pdelab at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-pdelab
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 534 bytes
Desc: OpenPGP digital signature
URL: <https://lists.dune-project.org/pipermail/dune-pdelab/attachments/20140512/78b1aa3a/attachment.sig>


More information about the dune-pdelab mailing list