I use libev, which requires pouring my data into void * so that it matches their predefined structures. I need to enable boost :: shared_ptr in void * and then return void * back to boost :: shared_ptr. Here is my code to do this
void foo(boost::shared_ptr<string>& a_string)
{
void* data = (void*)a_string.get();
boost::shared_ptr<string> myString((string*)data);
}
I'm sure this works fine, however, as my code is configured, I believe that all shared_ptr links to my string are out of scope, since this casting method does not increase the value of use_count, and therefore shared_ptr frees up memory while I still need this one.
Is there a way to manually increase / decrease the value of the use_count parameter? Ideally, I would increase the value of use_count when I applied void *, pass my void * to another function, return void * back to shared_ptr and decrease the value of use_count.
Or, if someone knows another solution to this problem, I can use any help.
source
share