Registered Member
|
We recently uncovered a memory leak that we were encountering, and discovered it was due to Eigen's resize mechanisms:
https://github.com/RobotLocomotion/drake/issues/5974 Specifically, we were storing symbolic variables which directly contained std::string variables. This was a problem if the strings were short enough for SSO, and would cause an unsafe memcpy-move, since the internal data was not invariant of the storage location (storing an offset into this). Specifically, in PlainObjectBase.h, under conservative_resize_like_impl, we encountered a snag here:
We have presently side-stepped the issue by making the Scalar type's std::string be stored in a std::shared_ptr<>, such that it is memcpy-movable: https://github.com/RobotLocomotion/drak ... 540ece84ae Utility for checking invariance: https://github.com/RobotLocomotion/drak ... able.h#L21 I noticed that there is NumTraits<T>::RequireInitialization (Memory.h), and a method called smart_copy. However, when looking at PlainObjectBase.h, I see:
which, I think (have not yet fully traced it out), ends up calling something like this (Memory.h):
Question: Is there something like NumTraits<T>::IsMemcpyMovable / RequireMoveConstructor, which would keep on the same codepaths (and would be true by default), but if it were false, it would explicitly move the objects? (maybe with a C++11 guard, that actually causes the appropriate move constructor via std::move). If not, do you have any suggestions for how this would be done? And would this be considered a bug of sorts (or an enhancement), something that I should send to the mailing list? Would it also be possible to update the memory leak portion of the Wiki to indicate this? |
Moderator
|
Sorry for late reply,
I guess c++11 exposes all the required type traits to automatically fix this issue on Eigen's side, leaving it as a "known pitfall" in C++98. Would you be able to propose a patch? |
Moderator
|
I added an entry: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1432
|
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]