Boost logo

Boost Users :

Subject: Re: [Boost-users] revisiting casting a boost::shared_ptr to void*
From: Chris Cleeland (chris.cleeland_at_[hidden])
Date: 2014-07-29 23:32:50


On Tue, Jul 29, 2014 at 9:15 PM, Gavin Lambert <gavinl_at_[hidden]>
wrote:

> 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.
>

Thank you. I think you understand what I'm trying to address.

In my case, it's a multi-shot callback. I don't think I'd need to do a
heap allocation/deallocation each cycle, but I'm also not sure that I want
to do a heap allocation in the first place.

> But you have to know what the C API is going to be doing with that
> pointer, or all bets are off.

In my case, the C API is stashing the value of the pointer in a container,
and passing that pointer value as an argument to the registered callback
function. That's it. The C code doesn't *do* anything with the pointer
because it treats it as a void*.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net