
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