[Dune] An issue with the new GridViews

Martin Nolte nolte at mathematik.uni-freiburg.de
Thu Jul 31 14:34:38 CEST 2008


Hi Oliver, hi Dune,

I think you have hit a point there. It seems we have to make a design decision 
here. Either, the grids return references to the grid views, or they return 
the object.

The advantage or returning references is that the segfault you describe will 
not happen. On the other hand, this means that the grid has to store the 
GridViews internally, i.e., for every level. While this makes sense it the 
grid view is a large data structure, this is an unnecessary overhead in the 
case of small objects like the DefaultGridViews. Moreover, I think it is 
harder to provide a default implementation in this case.

There is another point: An object can always model a reference, while a 
reference can never model an object. What I am saying is this: If the GridView 
is large and you do not want to store copies, you can always create a wrapper 
that store a pointer to the actual grid view and behaves the way a reference 
would behave.

My suggestion is to return an object because I think this concept is more 
flexible. But this has two consequences:
   1) You may not store the reference as you usually do in Dune.
   2) If the GridView is large, we should use an additional wrapper.
Personally, I think the problem of storing references is the more important one.

Maybe, we should also consider a third alternative: We could introduce a 
GridViewPointer, similar to the EntityPointer. While this may be the clearest 
concept, it also means a lot of overhead for the implementor of a grid (and 
this overhead is already very large).

In my opinion, this decision should be made as soon as possible, before too 
much code starts using the GridViews. I also think this decision should not be 
taken lightly. As I said, I prefer the current solution for its simplicity but 
I admit that is has a minor lack of clarity.

Cheers,

Martin



Oliver Sander wrote:
> Dear Dune!
> I just replaced a few uses of indexsets with grid views.  This is necessary
> to be able to eventually remove the deprecated begin() and end() methods
> of the IndexSet class.  I ran into one problem which I would like to point
> out to you.
> 
> The main change in P1Operator (in dune-disc) was to replace
> 
> const IndexSet& is;  // in P1OperatorBase
> 
> by
> 
> const GridView& gv;
> 
> However, while the methods leafIndexSet() and levelIndexSet() return
> const references to the index sets, the corresponding methods leafView()
> and levelView() return values.  If you store const references to them you
> run into strange problems with dangling references (read: segfaults).
> Therefore, the line in P1OperatorBase now reads
> 
> GridView gv;
> 
> I am not saying that handing over values instead of references is
> necessarily worse than handing over references.  However, one should
> be aware of the change, because the problems you get are hard to
> track down.
> 
> greetings,
> Oliver
> 

-- 
Martin Nolte <nolte at mathematik.uni-freiburg.de>

Universität Freiburg                                   phone: +49-761-203-5642
Abteilung für angewandte Mathematik                    fax:   +49-761-203-5632
Hermann-Herder-Straße 10
79104 Freiburg, Germany




More information about the Dune mailing list