Let me translate some of this, inline:
On Fri, Aug 5, 2011 at 6:38 AM, Mahmood Naderan
Hi I used boost::intrusive_ptr in a function, say foo(), like this:
boost::intrusive_ptr<BranchFeedback> theFeedback ( new BranchFeedback() ); std::vector< std::vector< BPredState > > theFetchState;
You have some container of BPredState objects. The container holds - manages - the objects, not just intrusive_ptrs to the objects. The objects have internal reference counts, that are probably each initially set to 0.
.... theFeedback->theBPState = &theFetchState[anIndex][!anOne];
you set an intrusive_ptr to the raw pointer of one of the BPredState objects inside the container. Its ref count probably goes to 1.
The problem is when foo() reaches the end (I mean '}'), I get segmentation fault which points to
At the end of foo(), your container of objects is destroyed. It deletes all the BPredState objects. Regardless of their reference counts. You asked the container to manage those objects, not just intrusive_ptrs to the objects, so when the container is done, the objects are gone.
~intrusive_ptr() { if(p_ != 0) intrusive_ptr_release(p_); }
the intrusive_ptr to one of the BPredObjects is then destroyed. It is currently pointing to an already destroyed BPredObject. It tries to decrement the ref count, probably setting it to 0. It tries to delete the already deleted object...
I thought I used the intrusive_ptr in a correct way. Is there any consideration that I missed? Thanks,
If you are managing via intrusive_ptrs, then make sure ALL management is done via intrusive_ptrs. Don't delete the objects from behind the intrusive_ptr's back. Tony