RTT::Event

Hi,

Event& operator=(boost::shared_ptr implementation)
{
if (this->impl == implementation)
return *this;
this->impl = boost::dynamic_pointer_cast< detail::EventBase >(implementation);
if ( !this->impl && implementation ) {
log(Error) << "Tried to assign Event '"<< mname <<"' from incompatible type."<< endlog();
}
return *this;
}

About the code sample taken from Event.hpp: should this->impl get deleted before assigning a new implementation (like equivalent operator in Command.hpp)?
 
Sander.

RTT::Event

Quoting Vandenbroucke Sander <Sander [dot] Vandenbroucke [..] ...>:

> Hi,
>
> Event& operator=(boost::shared_ptr implementation)
> {
> if (this->impl == implementation)
> return *this;
> this->impl = boost::dynamic_pointer_cast<
> detail::EventBase >(implementation);
> if ( !this->impl && implementation ) {
> log(Error) << "Tried to assign Event '"<< mname <<"'
> from incompatible type."<< endlog();
> }
> return *this;
> }
>
> About the code sample taken from Event.hpp: should this->impl get
> deleted before assigning a new implementation (like equivalent
> operator in Command.hpp)?

No, because this->impl is a shared pointer, which cleans up (delete)
itself when assigned to a new object.

Ideally, Command.hpp should use a shared pointer as well for the impl
pointer, as there is a substantial memory gain from it when registering
a command to the TaskContext interface. Now a clone() is taken, but if
the impl pointer was shared, the original could be re-used, which cuts
command memory consumption in half. Same for methods. I don't know why
I didn't do that at the time.

Peter