Jump to content
  • Advertisement
Sign in to follow this  
moeron

Tracing deletions from boost::shared_ptr

This topic is 4623 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to track down a very strange bug that I cannot reproduce on my own machine. Basically, some data is "disappearing" without firing off any error messages to let my beta testers know what the hell is happening. So I've come to the conclusion that this problem must be caused by something falling out of scope prematurely or otherwise being corrupted or destroyed. The problem is I am not very experianced with the boost libraries. I use the smart pointers and I have messed around with the tokenizer, but thats about it. So basically, what is my best bet to be able to log whenever a boost::shared_ptr enters its destructor or actually, when it enters the destructor and actually deletes the pointer. Is there some kind of debug hook function I can write, or is it just better to make my own derived class of boost::shared_ptr? Thanks for any advice, and sorry if I am not providing enough information, but I'm just trying to give the basic jist without going into too much useless detail. moe.ron

Share this post


Link to post
Share on other sites
Advertisement
boost::shared_ptr allows you to specify a "deleter" when you construct the pointer that will be invoked when the underlying pointer would actually be destroyed.

Check out the docs, specifically the template<class Y, class D> shared_ptr(Y * p, D d) form of the constructor.

It's not likely that shared_ptr itself is prematurely deleting, more likely that you mismanaging your shared_ptrs so that all references to an underyling pointer are destroyed. In any case, it may be easier for you to put debug notification code inside the destructor of the class whose pointer is held by the shared_ptr. It will be easier than modifying all your shared_ptr constructions.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
boost::shared_ptr allows you to specify a "deleter" when you construct the pointer that will be invoked when the underlying pointer would actually be destroyed.

Check out the docs, specifically the template<class Y, class D> shared_ptr(Y * p, D d) form of the constructor.


Thanks, that is exactly what I am looking for, and it was right in front of my face. Ugh... =)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!