On 30/07/2014 14:01, Michael Powell wrote:
Not to beat a dead horse. But here's an apt analogy: I could be wrong, but you are dividing by zero and not expecting a div by zero exception (or worse) to occur.
I don't see how that's even slightly a valid analogy. In any case, what the OP needs to do is to characterise the lifetime of the raw pointer as used by the C API, and *absolutely guarantee* that some shared_ptr exists at least as long as that. There are various techniques for doing this, depending on what that lifetime is -- for example, if it's a single-shot callback then Dominique's suggestion might be reasonable, if you don't mind paying an extra allocation/deallocation each cycle. If it's a multi-shot callback then it may be better to make a connection-management object that registers/unregisters with the C API and then manage the lifecycle of *that* object appropriately. There's many methods. But you have to know what the C API is going to be doing with that pointer, or all bets are off.