-
Notifications
You must be signed in to change notification settings - Fork 287
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
Proposal: Use aliasing constructor of shared_ptr for BodyNodePtr #905
Comments
This sounds really good to me as I generally prefer using STL. I think the custom smart pointer was introduced because we believed there was no solution with The disadvantage seems fair enough and to make sense. Also, I guess this change would go into the next major release as it would be API breaking changes. |
Yeah, I wish I had known about the aliasing constructor back then. It would have saved me a significant amount of time and effort. Although I don't mind the fact that I got some practice creating a custom smart pointer type. Of course it shouldn't come as any surprise that the people on the ISO standards committee already anticipated our needs ahead of time. It should definitely target dart-7, due to the slight API breakages. Should that be master branch, or should I create another branch (e.g. |
I think master should be the most bleeding edge branch; so let's (1) create release-6.3 for adding new features that don't break API compatibility and are expected to be released soon, and (2) bump up the master branch version to 7.0.0. |
I am strongly in favor of this change. When @mkoval and I were originally analyzing the resource management problem for The downside of not being able to implictly cast a raw pointer to a shared pointer seems relatively minor. In most situations I can think of, the raw pointer would be derived from a shared pointer anyway, and functions that require a shared pointer are making an ownership demand that it is useful to make explicit in these situations. |
Yeah, it doesn't help that information on the aliasing constructor tends to be one small footnote in a massive list of different ways of constructing a I think the aliasing constructor deserves to have a big billboard at the top of any documentation about |
I was aware of this when we were implementing the custom pointer types. The aliasing constructor not sufficient for our needs because there is no mechanism to transfer ownership of an object that between owners. This is necessary to implement any of DART's This is a fundamental limitation of the way Aliasing is implemented by sharing one control block between multiple In summary: we either have to use a custom |
Oh, thanks for that reminder! I have to admit, I forgot about that part of the motivation for the custom pointer type. That being said, I'm pretty sure we can still get it to work using the aliasing constructor. Here would be my proposal:
When we use the Because naturally if one layer of |
While I believe I'll be able to make this work for the The only way I can fathom using For now, I think my plan will be to change the memory management for At the very least, we'll have a unified memory management system for all the |
After implementing this, the unit tests have revealed one major flaw:
The object returned by I still feel like it should be possible to make this work the way we want, but admittedly I'm a bit stumped at the moment over how to resolve this. I can easily think of ways to make the If anyone has thoughts or ideas to try out, I'd love to hear them. Otherwise, I'm going to keep flexing my creativity to see if I can come up with something that allows both types of pointers to have the expected behavior. |
I have a partial solution, although there's one big issue with it, which I'll mention at the end. We can create a meta-object which, for now, I'll refer to as When you call Now suppose you create a second Now here's the big drawback: This makes it impossible to partially delete a So there are two questions: (1) Would this be worth it, if no other solution is available? (2) Is there a better solution that I haven't thought of yet? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
I recently stumbled across the marvelously useful "aliasing constructor" of
std::shared_ptr
. The aliasing constructor allows astd::shared_ptr
to refer to an arbitrary object while its reference count is tied to another arbitrary object. We can apply this toBodyNodePtr
by making it astd::shared_ptr
which refers to aBodyNode
object while its reference count is tied to theSkeleton
object that owns theBodyNode
.This has the added benefit of allowing us to cast
BodyNodePtr
to aFramePtr
and generally enabling us to unify the memory management of all shared DART objects under the umbrella ofstd::shared_ptr
. So for example we could have astd::vector<FramePtr>
which contains a set of bothBodyNodePtr
andSimpleFramePtr
objects, as well as otherFrame
types. This memory management scheme would also work forJointPtr
.The one disadvantage is we'll lose the ability to implicitly cast a raw
BodyNode*
to a smartBodyNodePtr
, becausestd::shared_ptr
(very reasonably) does not allow implicit conversion from raw pointers. This could have a significant impact on some users and some DART-dependent frameworks, so I'd especially like to hear from Aikido developers (paging @jslee02 @gilwoolee, and @mkoval @psigen if you're still involved or interested in this topic). I think this disadvantage would be well worth the benefits of throwing away a custom smart pointer class and having unified, consistent memory management.The text was updated successfully, but these errors were encountered: