Comments (4)
Upvote for transforming every unique ptr into shared. I think it makes more sense given the application of the handler. I don't see why the ownership should be reserved. Feel free to close/edit my other PR to use shared pointers instead.
from bipedal-locomotion-framework.
I just realized that the issue is more complex than what I initially thought. The basic problem is that ownership is not clear. Having a unique_ptr
to an object means that it is owned by a single actor. Hence, it is weird that when getting something out of it (getGroup
) you get again a unique_ptr
. It seems that someone can have unique possession of a part of a bigger object uniquely owned by someone else (this is not completely the case, but stick with me for a moment *).
It is like saying that you own a house and you only have the key of it, but someone else owns a room. So, what happens when I want to destroy the house? Also, that room should be destroyed right?
I was thinking that it may be more reasonable that getGroup
returns a weak_ptr
instead. This avoids problems in case some groups, for some reason, has a pointer to the outer group (this happens more often than expected, unfortunately). In addition, returning a weak_ptr
makes it clear to whom the ownership belongs. If I decide to burn down the house, that poor guy who had the key of the room will find just a bunch of ashes (when try to lock
an empty shared_ptr
is returned).
So I tried.. and it did not work. Here you could say "I knew it" (*). Yes, because getGroup
doesn't actually return a pointer to a part of the whole object, but rather a copy of it. In other words, the other guy own a key to an exact copy of the room that I just destroyed in my house. Hence, when returning a weak_ptr
, I was always getting an empty pointer because the copy I was creating was being deallocated when going out of the scope of getGroup
. In addition, returning a weak_ptr
makes sense only if there is a shared_ptr
somewhere actually owning the object.
Indeed, this is my fault 😁. It is a direct consequence of a review comment I made about the possibility to set
parameters. In fact, before the parameter handler was owning a reference to a searchable (instead of a copy of it), hence when doing getGroup
a new object was created with again a reference to the group in the initial object. In this case, the ownership problem was a bit different: neither I nor the other guy actually possessed the house, but a third entity with the original version of the searchable.
Here comes the other problem though. If I get a group and then I modify a parameter, this modification is not reflected to the original object owning the group. This was initially possible, but no more after the modifications necessary to have a set
method.
So I guess that your problem can be solved via the following:
A a1, a2;
a1.initialize(params->getGroup("foo"));
a2.initialize(params->getGroup("foo"));
because you are actually getting two different copies of the same object. In this case it makes more sense to return a unique_ptr
instead of a shared_ptr
because you are actually generating whole new objects.
I don't really like this solution since I would like to have a pointer to a part of the whole, rather than a copy of it.
from bipedal-locomotion-framework.
@traversaro @S-Dafarra do you have any other ideas?
All what @S-Dafarra just wrote, plus:
Are you sure the issue is in the getGroup
method signature, and not in the fact that the A::initialize
takes a unique_ptr
?
from bipedal-locomotion-framework.
I tried to fix the ownership and modifiability issues with this PR: #18
from bipedal-locomotion-framework.
Related Issues (20)
- Support QPIK and TSID QP problems with no constraint HOT 5
- Add the possibility to control a subset of coordinates in TSID:SE3Task HOT 1
- Handle deprecation of ``transformClient`` HOT 1
- Add the possibility to dinamically add and remove tasks in the IK/TSID
- Add minimization of joint torques to TSID HOT 7
- Add possibility to get the optimizer logs for TSID HOT 1
- Add the possibility to set tollerances on equality constraints for TSID HOT 1
- Add the possibility to get the ControllerOutput in TSID:SE3Task
- Make the project compiling with python 3.12 HOT 1
- Unable to locate the python bindings after #752 HOT 8
- Change how external contacts are defined, loaded, and stored from configuration files HOT 2
- vcpkg CI job fails at vcpkg install tomlplusplus November 2023 HOT 3
- Conda force CI failure macOS December 2023 HOT 1
- ImportError: arg(): could not convert default argument into a Python object when using BLF HOT 18
- Data logged by the YarpRobotLoggerDevice corrupted after 767 HOT 1
- Gravity task and distance task QPIK test fails on windows HOT 21
- CentroidalMPC test fails with ma97_factor Matrix found to be singular HOT 13
- YARPRobotLoggerDevice: Do not try to populate FTs:: channels if m_streamFTSensors is false
- YarpSensorBridge fails in attaching FT IMU in simulation HOT 5
- YARPRobotLoggerDevice: excessively long time horizon for signals logged with YARP_CLOCK HOT 20
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bipedal-locomotion-framework.