craig
* Remove POD requirement for keys and values! (austern)
Is this not actually true?
Cheers,
Andrew
Ahem, *mumble* I had forgotten about that. You're absolutely right.
Looking at the stack trace, it looks like the problem is with the
interaction between dense_hash_map and shared_ptr. I don't know
anything about boost, but it may not be safe to use in the way you're
using it. Can you copy shared_ptr's around, and delete the old one,
and have everything be ok?
The crash is happening at resize time: we're copying all the stuff
from the old hashtable to a new, bigger one, and then deleting the old
one. That's where the crash is happening. Does copying a shared_ptr
transfer ownership or something, so that deleting the old one is no
longer safe?
I'm not saying the problem is with the hashtable code, but the use of
boost as the value type -- especially given the fact the boost
destructor is what is triggering the crash -- does make it a bit hard
to disentangle the possible causes.
Would it be possible to rejigger your application so it uses something
other than a shared_ptr, to see if it causes the same problems?
Alternately, you can just run this through gdb and see what this looks
like during ~shared_ptr. Maybe there will be obvious corruption, or
something else that points what might be going wrong.
craig
I meant, I'm not saying the problem is *not* with the hashtable code.
Too many negatives.
If you can't debug this, and are open to making the source available,
maybe you can put it up somewhere so we can try to reproduce the
problem here.
craig
Some of these pointer values look fishy to me.. the one starting with
0xffff in frame #17 particular (and #13). Are you sure there isn't some
sort of memory corruption going on in another part of the program?
> destroy_buckets looks like it goes through and calls destructors
> manually on each item being moved. I don't think boost::shared_ptr's
> like their destructors being called? The object with the destructor
> being called should already have been deleted?
This should be ok as long as the destructor is only called once (ie, we
don't call both the destructor and then delete to free up the memory).
> Can anyone see the problem with what I am doing? Is it possible to
> resize a google::dense_hash_map with value_type of boost::shared_ptr<T>
> correctly with items that have previously been deleted?
It works in my simple test code, and I'm sure that we have a more
complicated setup like yours somewhere in our production code which runs
fine. (or maybe we're in for a nasty surprise soon!)
Wes
These are stack-allocated objects. The one in #13 is expected: we
grow the hasthable by creating a new one on the stack as scratch
space, and it's the one getting destroyed.
In #17, it looks like the insert that's being done is of a
stack-allocated object as well. That should be fine; I don't think
that would cause any problems.
craig