|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-02-14 18:06:23
Dave Nay wrote:
> Hi All!
>
> I am using a third party library where I enqueue a series of events.
> Each of these events allows the passing of a user context void*. I
> am attempting to pass the address of a boost::shared_ptr as my
> context.
>
> typedef boost::shared_ptr<CBuffer> CBufferPtr;
>
> for (i = 0; i < PREQUEUESIZE; i++)
> {
> handle = RegisterBuffer(buffer->m_pBCAMBuffer, m_AOISize);
> QueueBuffer( handle, &buffer ); // The second parameter is a
> void* user context data
> }
>
> In the above code "buffer" is my shared_ptr.
If buffer is of type CBufferPtr here, you pass a pointer to it to the
library, an entity of type CBufferPtr*. This implies that your 'buffer'
variable will be alive until the third-party library is done with it. Will
it?
> Later, in my event handler I have the following:
>
> CBufferPtr buffer = static_cast<CBufferPtr>(result.Context());
Here you try to cast the context (logically of type CBufferPtr*, physically
of type void*) to CBufferPtr. Nothing good can come from this. :-) The
opposite of the above should be
CBufferPtr buffer = *static_cast<CBufferPtr*>(result.Context());
but, without seeing the particulars of your code and the specification of
the third-party library, I can't tell whether it's right.
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