-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing issue #779 #1151
Fixing issue #779 #1151
Conversation
Not really aware of the details here, but what about using std::shared_ptr instead of raw pointers? Passing by shared_ptr only when lifetime, or ownership is involved, and by raw pointer std::shared_ptr::get() to interact with non-owning functions/classes. cpp core guidelines From boost::shared_ptr it meets the CopyConstructible, MoveConstructible, CopyAssignable and MoveAssignable requirements. |
We do have smart pointers in DGtal (http://dgtal.org/doc/nightly/moduleCloneAndReference.html). This issue seems to be related to bad object lifetime management in this container. |
I agree that
I suppose that we choose the third solution ? Perhaps with |
This reverts commit 9bfd67d. Conflicts: src/DGtal/images/ImageContainerBySTLMap.ih
/// Since the domain is not mutable, not assignable, | ||
/// it is shared by all the copies of *this | ||
DomainPtr myDomainPtr; | ||
std::shared_ptr<const Domain> myDomainPtr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't it be a DGtal::CountedPtr ?
just for consistency..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it can ! However CountedPtr
has no conversion from CountedPtr<T>
to CountedPtr<const T>
that may be necessary here. I will think about adding it...
Sorry for being late on this PR. Let me start with some general comments:
and member class could, for instance (several other options are possible as members, see doc page), be:
(most image containers have been created before Const/Alias stuff). Lifetime of the domain must be larger than the container lifetime (i.e.: no domains on the stack)
I know that @elcerdo has very different point of view of the data management: constructors always copy the data and when the user don't want to have memory copies, he/she wraps the data into a lightweight facade (with exact same interface)... It is not was is currently implemented in DGtal but that's maybe part of the discussion. (ping @JacquesOlivierLachaud ) |
OK but that means that the caller controls the lifetime of
No because
I don't think this is a good solution but I have choose it for compatibility reasons with current code. I don't like the idea that classes have to deal with their parameters size when they do not control their type (because of a template) and thus, I like @elcerdo solution even if it requires more works for the user. A mixed solution may be what some linear algebra library uses (like |
Just a silly C++11 question... The rvalue constructor of ConstAlias prevents the passing of temp objects. |
In order to avoid unecessary copies.
After discussing with @JacquesOlivierLachaud, it seems that using |
@@ -88,14 +89,19 @@ namespace DGtal | |||
const T& operator*() const throw() {return *myPtr;} | |||
const T* operator->() const throw() {return myPtr.get();} | |||
const T* get() const throw() {return myPtr.get();} | |||
|
|||
|
|||
template < typename U = T, typename std::enable_if< ! std::is_const<U>::value >::type* = nullptr > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind commenting a bit these lines ? (Like forces the compiler to choose the const version without copy whenever possible)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was a very comprehensible line, especially the typename U = T
Ok, I will add a comment 😉 ( in doxygen style or just for the devs ? )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for devs I think.
PR Description
The issue #779 comes from the fact that
ImageContainerBySTLMap
stores his domain by pointer.But readers create domain on the stack before constructing images so that the pointer is invalid as soon as the reader ends.
Therefore, a solution is to store the domain by value, like other image containers.
But, doing so (like in this PR), leads to compilation errors when the domain is not assignable. It is the case when using a
DigitalSetDomain
, like intests/geometry/volumes/distance/testPowerMap
.In fact, this problem arises for all
CTrivialConstImage
models that store the domain by value, since it is a refinement ofboost::Assignable
.Any suggestion ?
Checklist
cmake
mode (otherwise, Travis C.I. will fail).