[gecode-users] Best practice to use a shared_ptr in a gecode solver

Gustavo Gutierrez gustavo.ggutierrez at gmail.com
Tue Nov 4 03:58:57 CET 2014


Dear Gecode users,

This is probably a naive question and very related to C++. However, it is
quite related to gecode as well. In my use case I have a shared pointer to
an object that contains all the information of a problem instance. As
usual, the constructor is where the CSP is defined and that object is
passed as an argument to it.

In addition, I implemented a brancher that also require some of the
information pointed by the shared pointer.  Note that this infromation is
not actually needed to construct the brancher but when computing a choice.
I have tried several ways to make both the brancher and the shared_pointer
happy with their respective requirements. However I have found myself in
the following situation.

When I add the shared_pointer as an attribute to the brancher I get the
shared pointer reference counter messed up. The reason is that the brancher
does not actually have a destructor and hence the shared_pointer counter is
never decremented and the owned pointer is never destructed at the end of
the solver execution. I tried to explicitly call the destructor of the
shared pointer in the dispose method of the brancher. However, it seems
that the brancher gets copied more times than the dispose method is called.

Is there a way to integrate both approaches smoothly?. Probably I am
overlooking something.

Regards,
Gustavo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20141103/905e52be/attachment.html>


More information about the users mailing list